<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE GADTs #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}</span><span>
</span><span id="line-3"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Cmm.Switch</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-4"></span><span>     </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier">SwitchTargets</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-5"></span><span>     </span><span class="annot"><a href="GHC.Cmm.Switch.html#mkSwitchTargets"><span class="hs-identifier">mkSwitchTargets</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-6"></span><span>     </span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsCases"><span class="hs-identifier">switchTargetsCases</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsDefault"><span class="hs-identifier">switchTargetsDefault</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsRange"><span class="hs-identifier">switchTargetsRange</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsSigned"><span class="hs-identifier">switchTargetsSigned</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-7"></span><span>     </span><span class="annot"><a href="GHC.Cmm.Switch.html#mapSwitchTargets"><span class="hs-identifier">mapSwitchTargets</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsToTable"><span class="hs-identifier">switchTargetsToTable</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsFallThrough"><span class="hs-identifier">switchTargetsFallThrough</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-8"></span><span>     </span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsToList"><span class="hs-identifier">switchTargetsToList</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#eqSwitchTargetWith"><span class="hs-identifier">eqSwitchTargetWith</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span>     </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchPlan"><span class="hs-identifier">SwitchPlan</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-11"></span><span>     </span><span class="annot"><a href="GHC.Cmm.Switch.html#targetSupportsSwitch"><span class="hs-identifier">targetSupportsSwitch</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-12"></span><span>     </span><span class="annot"><a href="GHC.Cmm.Switch.html#createSwitchPlan"><span class="hs-identifier">createSwitchPlan</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-13"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-14"></span><span>
</span><span id="line-15"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-16"></span><span>
</span><span id="line-17"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-18"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html"><span class="hs-identifier">GHC.Driver.Session</span></a></span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html"><span class="hs-identifier">GHC.Cmm.Dataflow.Label</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier">Label</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-20"></span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Maybe.html#"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.List.html#"><span class="hs-identifier">Data.List</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.OldList.html#groupBy"><span class="hs-identifier">groupBy</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Function.html#"><span class="hs-identifier">Data.Function</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.Function.html#on"><span class="hs-identifier">on</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../containers/src/Data.Map.html#"><span class="hs-identifier">Data.Map</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">M</span></span><span>
</span><span id="line-25"></span><span>
</span><span id="line-26"></span><span class="hs-comment">-- Note [Cmm Switches, the general plan]</span><span>
</span><span id="line-27"></span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-28"></span><span class="hs-comment">--</span><span>
</span><span id="line-29"></span><span class="hs-comment">-- Compiling a high-level switch statement, as it comes out of a STG case</span><span>
</span><span id="line-30"></span><span class="hs-comment">-- expression, for example, allows for a surprising amount of design decisions.</span><span>
</span><span id="line-31"></span><span class="hs-comment">-- Therefore, we cleanly separated this from the Stg &#8594; Cmm transformation, as</span><span>
</span><span id="line-32"></span><span class="hs-comment">-- well as from the actual code generation.</span><span>
</span><span id="line-33"></span><span class="hs-comment">--</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- The overall plan is:</span><span>
</span><span id="line-35"></span><span class="hs-comment">--  * The Stg &#8594; Cmm transformation creates a single `SwitchTargets` in</span><span>
</span><span id="line-36"></span><span class="hs-comment">--    emitSwitch and emitCmmLitSwitch in GHC.StgToCmm.Utils.</span><span>
</span><span id="line-37"></span><span class="hs-comment">--    At this stage, they are unsuitable for code generation.</span><span>
</span><span id="line-38"></span><span class="hs-comment">--  * A dedicated Cmm transformation (GHC.Cmm.Switch.Implement) replaces these</span><span>
</span><span id="line-39"></span><span class="hs-comment">--    switch statements with code that is suitable for code generation, i.e.</span><span>
</span><span id="line-40"></span><span class="hs-comment">--    a nice balanced tree of decisions with dense jump tables in the leafs.</span><span>
</span><span id="line-41"></span><span class="hs-comment">--    The actual planning of this tree is performed in pure code in createSwitchPlan</span><span>
</span><span id="line-42"></span><span class="hs-comment">--    in this module. See Note [createSwitchPlan].</span><span>
</span><span id="line-43"></span><span class="hs-comment">--  * The actual code generation will not do any further processing and</span><span>
</span><span id="line-44"></span><span class="hs-comment">--    implement each CmmSwitch with a jump tables.</span><span>
</span><span id="line-45"></span><span class="hs-comment">--</span><span>
</span><span id="line-46"></span><span class="hs-comment">-- When compiling to LLVM or C, GHC.Cmm.Switch.Implement leaves the switch</span><span>
</span><span id="line-47"></span><span class="hs-comment">-- statements alone, as we can turn a SwitchTargets value into a nice</span><span>
</span><span id="line-48"></span><span class="hs-comment">-- switch-statement in LLVM resp. C, and leave the rest to the compiler.</span><span>
</span><span id="line-49"></span><span class="hs-comment">--</span><span>
</span><span id="line-50"></span><span class="hs-comment">-- See Note [GHC.Cmm.Switch vs. GHC.Cmm.Switch.Implement] why the two module are</span><span>
</span><span id="line-51"></span><span class="hs-comment">-- separated.</span><span>
</span><span id="line-52"></span><span>
</span><span id="line-53"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-54"></span><span class="hs-comment">-- Note [Magic Constants in GHC.Cmm.Switch]</span><span>
</span><span id="line-55"></span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-56"></span><span class="hs-comment">--</span><span>
</span><span id="line-57"></span><span class="hs-comment">-- There are a lot of heuristics here that depend on magic values where it is</span><span>
</span><span id="line-58"></span><span class="hs-comment">-- hard to determine the &quot;best&quot; value (for whatever that means). These are the</span><span>
</span><span id="line-59"></span><span class="hs-comment">-- magic values:</span><span>
</span><span id="line-60"></span><span>
</span><span id="line-61"></span><span class="hs-comment">-- | Number of consecutive default values allowed in a jump table. If there are</span><span>
</span><span id="line-62"></span><span class="hs-comment">-- more of them, the jump tables are split.</span><span>
</span><span id="line-63"></span><span class="hs-comment">--</span><span>
</span><span id="line-64"></span><span class="hs-comment">-- Currently 7, as it costs 7 words of additional code when a jump table is</span><span>
</span><span id="line-65"></span><span class="hs-comment">-- split (at least on x64, determined experimentally).</span><span>
</span><span id="line-66"></span><span class="annot"><a href="GHC.Cmm.Switch.html#maxJumpTableHole"><span class="hs-identifier hs-type">maxJumpTableHole</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span>
</span><span id="line-67"></span><span id="maxJumpTableHole"><span class="annot"><span class="annottext">maxJumpTableHole :: Integer
</span><a href="GHC.Cmm.Switch.html#maxJumpTableHole"><span class="hs-identifier hs-var hs-var">maxJumpTableHole</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">7</span></span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span class="hs-comment">-- | Minimum size of a jump table. If the number is smaller, the switch is</span><span>
</span><span id="line-70"></span><span class="hs-comment">-- implemented using conditionals.</span><span>
</span><span id="line-71"></span><span class="hs-comment">-- Currently 5, because an if-then-else tree of 4 values is nice and compact.</span><span>
</span><span id="line-72"></span><span class="annot"><a href="GHC.Cmm.Switch.html#minJumpTableSize"><span class="hs-identifier hs-type">minJumpTableSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-73"></span><span id="minJumpTableSize"><span class="annot"><span class="annottext">minJumpTableSize :: Int
</span><a href="GHC.Cmm.Switch.html#minJumpTableSize"><span class="hs-identifier hs-var hs-var">minJumpTableSize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">5</span></span><span>
</span><span id="line-74"></span><span>
</span><span id="line-75"></span><span class="hs-comment">-- | Minimum non-zero offset for a jump table. See Note [Jump Table Offset].</span><span>
</span><span id="line-76"></span><span class="annot"><a href="GHC.Cmm.Switch.html#minJumpTableOffset"><span class="hs-identifier hs-type">minJumpTableOffset</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span>
</span><span id="line-77"></span><span id="minJumpTableOffset"><span class="annot"><span class="annottext">minJumpTableOffset :: Integer
</span><a href="GHC.Cmm.Switch.html#minJumpTableOffset"><span class="hs-identifier hs-var hs-var">minJumpTableOffset</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">2</span></span><span>
</span><span id="line-78"></span><span>
</span><span id="line-79"></span><span>
</span><span id="line-80"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-81"></span><span class="hs-comment">-- Switch Targets</span><span>
</span><span id="line-82"></span><span>
</span><span id="line-83"></span><span class="hs-comment">-- Note [SwitchTargets]</span><span>
</span><span id="line-84"></span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-85"></span><span class="hs-comment">--</span><span>
</span><span id="line-86"></span><span class="hs-comment">-- The branches of a switch are stored in a SwitchTargets, which consists of an</span><span>
</span><span id="line-87"></span><span class="hs-comment">-- (optional) default jump target, and a map from values to jump targets.</span><span>
</span><span id="line-88"></span><span class="hs-comment">--</span><span>
</span><span id="line-89"></span><span class="hs-comment">-- If the default jump target is absent, the behaviour of the switch outside the</span><span>
</span><span id="line-90"></span><span class="hs-comment">-- values of the map is undefined.</span><span>
</span><span id="line-91"></span><span class="hs-comment">--</span><span>
</span><span id="line-92"></span><span class="hs-comment">-- We use an Integer for the keys the map so that it can be used in switches on</span><span>
</span><span id="line-93"></span><span class="hs-comment">-- unsigned as well as signed integers.</span><span>
</span><span id="line-94"></span><span class="hs-comment">--</span><span>
</span><span id="line-95"></span><span class="hs-comment">-- The map may be empty (we prune out-of-range branches here, so it could be us</span><span>
</span><span id="line-96"></span><span class="hs-comment">-- emptying it).</span><span>
</span><span id="line-97"></span><span class="hs-comment">--</span><span>
</span><span id="line-98"></span><span class="hs-comment">-- Before code generation, the table needs to be brought into a form where all</span><span>
</span><span id="line-99"></span><span class="hs-comment">-- entries are non-negative, so that it can be compiled into a jump table.</span><span>
</span><span id="line-100"></span><span class="hs-comment">-- See switchTargetsToTable.</span><span>
</span><span id="line-101"></span><span>
</span><span id="line-102"></span><span>
</span><span id="line-103"></span><span class="hs-comment">-- | A value of type SwitchTargets contains the alternatives for a 'CmmSwitch'</span><span>
</span><span id="line-104"></span><span class="hs-comment">-- value, and knows whether the value is signed, the possible range, an</span><span>
</span><span id="line-105"></span><span class="hs-comment">-- optional default value and a map from values to jump labels.</span><span>
</span><span id="line-106"></span><span class="hs-keyword">data</span><span> </span><span id="SwitchTargets"><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-var">SwitchTargets</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-107"></span><span>    </span><span id="SwitchTargets"><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-var">SwitchTargets</span></a></span></span><span>
</span><span id="line-108"></span><span>        </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>                       </span><span class="hs-comment">-- Signed values</span><span>
</span><span id="line-109"></span><span>        </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">)</span><span>         </span><span class="hs-comment">-- Range</span><span>
</span><span id="line-110"></span><span>        </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span class="hs-special">)</span><span>              </span><span class="hs-comment">-- Default value</span><span>
</span><span id="line-111"></span><span>        </span><span class="hs-special">(</span><span class="annot"><a href="../../containers/src/Data.Map.Internal.html#Map"><span class="hs-identifier hs-type">M.Map</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span class="hs-special">)</span><span>      </span><span class="hs-comment">-- The branches</span><span>
</span><span id="line-112"></span><span>    </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940717"><span id="local-6989586621680940719"><span id="local-6989586621680940734"><span class="annot"><span class="annottext">Int -&gt; SwitchTargets -&gt; ShowS
[SwitchTargets] -&gt; ShowS
SwitchTargets -&gt; String
(Int -&gt; SwitchTargets -&gt; ShowS)
-&gt; (SwitchTargets -&gt; String)
-&gt; ([SwitchTargets] -&gt; ShowS)
-&gt; Show SwitchTargets
forall a.
(Int -&gt; a -&gt; ShowS) -&gt; (a -&gt; String) -&gt; ([a] -&gt; ShowS) -&gt; Show a
showList :: [SwitchTargets] -&gt; ShowS
$cshowList :: [SwitchTargets] -&gt; ShowS
show :: SwitchTargets -&gt; String
$cshow :: SwitchTargets -&gt; String
showsPrec :: Int -&gt; SwitchTargets -&gt; ShowS
$cshowsPrec :: Int -&gt; SwitchTargets -&gt; ShowS
</span><a href="../../base/src/GHC.Show.html#Show"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Show</span></a></span></span></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680940704"><span id="local-6989586621680940712"><span class="annot"><span class="annottext">SwitchTargets -&gt; SwitchTargets -&gt; Bool
(SwitchTargets -&gt; SwitchTargets -&gt; Bool)
-&gt; (SwitchTargets -&gt; SwitchTargets -&gt; Bool) -&gt; Eq SwitchTargets
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: SwitchTargets -&gt; SwitchTargets -&gt; Bool
$c/= :: SwitchTargets -&gt; SwitchTargets -&gt; Bool
== :: SwitchTargets -&gt; SwitchTargets -&gt; Bool
$c== :: SwitchTargets -&gt; SwitchTargets -&gt; Bool
</span><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></span></span></span><span class="hs-special">)</span><span>
</span><span id="line-113"></span><span>
</span><span id="line-114"></span><span class="hs-comment">-- | The smart constructor mkSwitchTargets normalises the map a bit:</span><span>
</span><span id="line-115"></span><span class="hs-comment">--  * No entries outside the range</span><span>
</span><span id="line-116"></span><span class="hs-comment">--  * No entries equal to the default</span><span>
</span><span id="line-117"></span><span class="hs-comment">--  * No default if all elements have explicit values</span><span>
</span><span id="line-118"></span><span class="annot"><a href="GHC.Cmm.Switch.html#mkSwitchTargets"><span class="hs-identifier hs-type">mkSwitchTargets</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../containers/src/Data.Map.Internal.html#Map"><span class="hs-identifier hs-type">M.Map</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span>
</span><span id="line-119"></span><span id="mkSwitchTargets"><span class="annot"><span class="annottext">mkSwitchTargets :: Bool
-&gt; (Integer, Integer)
-&gt; Maybe Label
-&gt; Map Integer Label
-&gt; SwitchTargets
</span><a href="GHC.Cmm.Switch.html#mkSwitchTargets"><span class="hs-identifier hs-var hs-var">mkSwitchTargets</span></a></span></span><span> </span><span id="local-6989586621680940702"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940702"><span class="hs-identifier hs-var">signed</span></a></span></span><span> </span><span id="local-6989586621680940701"><span class="annot"><span class="annottext">range :: (Integer, Integer)
</span><a href="#local-6989586621680940701"><span class="hs-identifier hs-var">range</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span id="local-6989586621680940700"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940700"><span class="hs-identifier hs-var">lo</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940699"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940699"><span class="hs-identifier hs-var">hi</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680940698"><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940698"><span class="hs-identifier hs-var">mbdef</span></a></span></span><span> </span><span id="local-6989586621680940697"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940697"><span class="hs-identifier hs-var">ids</span></a></span></span><span>
</span><span id="line-120"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
-&gt; (Integer, Integer)
-&gt; Maybe Label
-&gt; Map Integer Label
-&gt; SwitchTargets
</span><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-var">SwitchTargets</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940702"><span class="hs-identifier hs-var">signed</span></a></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940701"><span class="hs-identifier hs-var">range</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940696"><span class="hs-identifier hs-var">mbdef'</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940695"><span class="hs-identifier hs-var">ids'</span></a></span><span>
</span><span id="line-121"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-122"></span><span>    </span><span id="local-6989586621680940695"><span class="annot"><span class="annottext">ids' :: Map Integer Label
</span><a href="#local-6989586621680940695"><span class="hs-identifier hs-var hs-var">ids'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Map Integer Label -&gt; Map Integer Label
</span><a href="#local-6989586621680940694"><span class="hs-identifier hs-var">dropDefault</span></a></span><span> </span><span class="annot"><span class="annottext">(Map Integer Label -&gt; Map Integer Label)
-&gt; Map Integer Label -&gt; Map Integer Label
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label -&gt; Map Integer Label
</span><a href="#local-6989586621680940693"><span class="hs-identifier hs-var">restrict</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940697"><span class="hs-identifier hs-var">ids</span></a></span><span>
</span><span id="line-123"></span><span>    </span><span id="local-6989586621680940696"><span class="annot"><span class="annottext">mbdef' :: Maybe Label
</span><a href="#local-6989586621680940696"><span class="hs-identifier hs-var hs-var">mbdef'</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940692"><span class="hs-identifier hs-var">defaultNeeded</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940698"><span class="hs-identifier hs-var">mbdef</span></a></span><span>
</span><span id="line-124"></span><span>           </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe Label
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-125"></span><span>
</span><span id="line-126"></span><span>    </span><span class="hs-comment">-- Drop entries outside the range, if there is a range</span><span>
</span><span id="line-127"></span><span>    </span><span id="local-6989586621680940693"><span class="annot"><span class="annottext">restrict :: Map Integer Label -&gt; Map Integer Label
</span><a href="#local-6989586621680940693"><span class="hs-identifier hs-var hs-var">restrict</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Integer, Integer) -&gt; Map Integer Label -&gt; Map Integer Label
forall b. (Integer, Integer) -&gt; Map Integer b -&gt; Map Integer b
</span><a href="GHC.Cmm.Switch.html#restrictMap"><span class="hs-identifier hs-var">restrictMap</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940700"><span class="hs-identifier hs-var">lo</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940699"><span class="hs-identifier hs-var">hi</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-128"></span><span>
</span><span id="line-129"></span><span>    </span><span class="hs-comment">-- Drop entries that equal the default, if there is a default</span><span>
</span><span id="line-130"></span><span>    </span><span id="local-6989586621680940694"><span class="annot"><span class="annottext">dropDefault :: Map Integer Label -&gt; Map Integer Label
</span><a href="#local-6989586621680940694"><span class="hs-identifier hs-var hs-var">dropDefault</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680940690"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940690"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940698"><span class="hs-identifier hs-var">mbdef</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Label -&gt; Bool) -&gt; Map Integer Label -&gt; Map Integer Label
forall a k. (a -&gt; Bool) -&gt; Map k a -&gt; Map k a
</span><a href="../../containers/src/Data.Map.Internal.html#filter"><span class="hs-identifier hs-var">M.filter</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Label -&gt; Label -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">/=</span></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940690"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-131"></span><span>                </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Map Integer Label -&gt; Map Integer Label
forall a. a -&gt; a
</span><a href="../../base/src/GHC.Base.html#id"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-132"></span><span>
</span><span id="line-133"></span><span>    </span><span class="hs-comment">-- Check if the default is still needed</span><span>
</span><span id="line-134"></span><span>    </span><span id="local-6989586621680940692"><span class="annot"><span class="annottext">defaultNeeded :: Bool
</span><a href="#local-6989586621680940692"><span class="hs-identifier hs-var hs-var">defaultNeeded</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Integer
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="../../base/src/GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer Label -&gt; Int
forall k a. Map k a -&gt; Int
</span><a href="../../containers/src/Data.Map.Internal.html#size"><span class="hs-identifier hs-var">M.size</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940695"><span class="hs-identifier hs-var">ids'</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">/=</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940699"><span class="hs-identifier hs-var">hi</span></a></span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Integer
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940700"><span class="hs-identifier hs-var">lo</span></a></span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Integer
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">1</span></span><span>
</span><span id="line-135"></span><span>
</span><span id="line-136"></span><span>
</span><span id="line-137"></span><span class="hs-comment">-- | Changes all labels mentioned in the SwitchTargets value</span><span>
</span><span id="line-138"></span><span class="annot"><a href="GHC.Cmm.Switch.html#mapSwitchTargets"><span class="hs-identifier hs-type">mapSwitchTargets</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span>
</span><span id="line-139"></span><span id="mapSwitchTargets"><span class="annot"><span class="annottext">mapSwitchTargets :: (Label -&gt; Label) -&gt; SwitchTargets -&gt; SwitchTargets
</span><a href="GHC.Cmm.Switch.html#mapSwitchTargets"><span class="hs-identifier hs-var hs-var">mapSwitchTargets</span></a></span></span><span> </span><span id="local-6989586621680940684"><span class="annot"><span class="annottext">Label -&gt; Label
</span><a href="#local-6989586621680940684"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span id="local-6989586621680940683"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940683"><span class="hs-identifier hs-var">signed</span></a></span></span><span> </span><span id="local-6989586621680940682"><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940682"><span class="hs-identifier hs-var">range</span></a></span></span><span> </span><span id="local-6989586621680940681"><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940681"><span class="hs-identifier hs-var">mbdef</span></a></span></span><span> </span><span id="local-6989586621680940680"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940680"><span class="hs-identifier hs-var">branches</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-140"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
-&gt; (Integer, Integer)
-&gt; Maybe Label
-&gt; Map Integer Label
-&gt; SwitchTargets
</span><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-var">SwitchTargets</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940683"><span class="hs-identifier hs-var">signed</span></a></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940682"><span class="hs-identifier hs-var">range</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Label -&gt; Label) -&gt; Maybe Label -&gt; Maybe Label
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">Label -&gt; Label
</span><a href="#local-6989586621680940684"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940681"><span class="hs-identifier hs-var">mbdef</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Label -&gt; Label) -&gt; Map Integer Label -&gt; Map Integer Label
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">Label -&gt; Label
</span><a href="#local-6989586621680940684"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940680"><span class="hs-identifier hs-var">branches</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-141"></span><span>
</span><span id="line-142"></span><span class="hs-comment">-- | Returns the list of non-default branches of the SwitchTargets value</span><span>
</span><span id="line-143"></span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsCases"><span class="hs-identifier hs-type">switchTargetsCases</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-144"></span><span id="switchTargetsCases"><span class="annot"><span class="annottext">switchTargetsCases :: SwitchTargets -&gt; [(Integer, Label)]
</span><a href="GHC.Cmm.Switch.html#switchTargetsCases"><span class="hs-identifier hs-var hs-var">switchTargetsCases</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680940679"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940679"><span class="hs-identifier hs-var">branches</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Map Integer Label -&gt; [(Integer, Label)]
forall k a. Map k a -&gt; [(k, a)]
</span><a href="../../containers/src/Data.Map.Internal.html#toList"><span class="hs-identifier hs-var">M.toList</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940679"><span class="hs-identifier hs-var">branches</span></a></span><span>
</span><span id="line-145"></span><span>
</span><span id="line-146"></span><span class="hs-comment">-- | Return the default label of the SwitchTargets value</span><span>
</span><span id="line-147"></span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsDefault"><span class="hs-identifier hs-type">switchTargetsDefault</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span>
</span><span id="line-148"></span><span id="switchTargetsDefault"><span class="annot"><span class="annottext">switchTargetsDefault :: SwitchTargets -&gt; Maybe Label
</span><a href="GHC.Cmm.Switch.html#switchTargetsDefault"><span class="hs-identifier hs-var hs-var">switchTargetsDefault</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680940677"><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940677"><span class="hs-identifier hs-var">mbdef</span></a></span></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940677"><span class="hs-identifier hs-var">mbdef</span></a></span><span>
</span><span id="line-149"></span><span>
</span><span id="line-150"></span><span class="hs-comment">-- | Return the range of the SwitchTargets value</span><span>
</span><span id="line-151"></span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsRange"><span class="hs-identifier hs-type">switchTargetsRange</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">)</span><span>
</span><span id="line-152"></span><span id="switchTargetsRange"><span class="annot"><span class="annottext">switchTargetsRange :: SwitchTargets -&gt; (Integer, Integer)
</span><a href="GHC.Cmm.Switch.html#switchTargetsRange"><span class="hs-identifier hs-var hs-var">switchTargetsRange</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680940676"><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940676"><span class="hs-identifier hs-var">range</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940676"><span class="hs-identifier hs-var">range</span></a></span><span>
</span><span id="line-153"></span><span>
</span><span id="line-154"></span><span class="hs-comment">-- | Return whether this is used for a signed value</span><span>
</span><span id="line-155"></span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsSigned"><span class="hs-identifier hs-type">switchTargetsSigned</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-156"></span><span id="switchTargetsSigned"><span class="annot"><span class="annottext">switchTargetsSigned :: SwitchTargets -&gt; Bool
</span><a href="GHC.Cmm.Switch.html#switchTargetsSigned"><span class="hs-identifier hs-var hs-var">switchTargetsSigned</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span id="local-6989586621680940675"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940675"><span class="hs-identifier hs-var">signed</span></a></span></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940675"><span class="hs-identifier hs-var">signed</span></a></span><span>
</span><span id="line-157"></span><span>
</span><span id="line-158"></span><span class="hs-comment">-- | switchTargetsToTable creates a dense jump table, usable for code generation.</span><span>
</span><span id="line-159"></span><span class="hs-comment">--</span><span>
</span><span id="line-160"></span><span class="hs-comment">-- Also returns an offset to add to the value; the list is 0-based on the</span><span>
</span><span id="line-161"></span><span class="hs-comment">-- result of that addition.</span><span>
</span><span id="line-162"></span><span class="hs-comment">--</span><span>
</span><span id="line-163"></span><span class="hs-comment">-- The conversion from Integer to Int is a bit of a wart, as the actual</span><span>
</span><span id="line-164"></span><span class="hs-comment">-- scrutinee might be an unsigned word, but it just works, due to wrap-around</span><span>
</span><span id="line-165"></span><span class="hs-comment">-- arithmetic (as verified by the CmmSwitchTest test case).</span><span>
</span><span id="line-166"></span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsToTable"><span class="hs-identifier hs-type">switchTargetsToTable</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-167"></span><span id="switchTargetsToTable"><span class="annot"><span class="annottext">switchTargetsToTable :: SwitchTargets -&gt; (Int, [Maybe Label])
</span><a href="GHC.Cmm.Switch.html#switchTargetsToTable"><span class="hs-identifier hs-var hs-var">switchTargetsToTable</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940674"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940674"><span class="hs-identifier hs-var">lo</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940673"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940673"><span class="hs-identifier hs-var">hi</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680940672"><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940672"><span class="hs-identifier hs-var">mbdef</span></a></span></span><span> </span><span id="local-6989586621680940671"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940671"><span class="hs-identifier hs-var">branches</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-168"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="../../base/src/GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">-</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940670"><span class="hs-identifier hs-var">start</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Maybe Label
</span><a href="#local-6989586621680940669"><span class="hs-identifier hs-var">labelFor</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940668"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680940668"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940668"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940670"><span class="hs-identifier hs-var">start</span></a></span><span class="hs-glyph">..</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940673"><span class="hs-identifier hs-var">hi</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-169"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-170"></span><span>    </span><span id="local-6989586621680940669"><span class="annot"><span class="annottext">labelFor :: Integer -&gt; Maybe Label
</span><a href="#local-6989586621680940669"><span class="hs-identifier hs-var hs-var">labelFor</span></a></span></span><span> </span><span id="local-6989586621680940667"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940667"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Map Integer Label -&gt; Maybe Label
forall k a. Ord k =&gt; k -&gt; Map k a -&gt; Maybe a
</span><a href="../../containers/src/Data.Map.Internal.html#lookup"><span class="hs-identifier hs-var">M.lookup</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940667"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940671"><span class="hs-identifier hs-var">branches</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680940665"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940665"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Label -&gt; Maybe Label
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940665"><span class="hs-identifier hs-var">l</span></a></span><span>
</span><span id="line-171"></span><span>                                             </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940672"><span class="hs-identifier hs-var">mbdef</span></a></span><span>
</span><span id="line-172"></span><span>    </span><span id="local-6989586621680940670"><span class="annot"><span class="annottext">start :: Integer
</span><a href="#local-6989586621680940670"><span class="hs-identifier hs-var hs-var">start</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940674"><span class="hs-identifier hs-var">lo</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;=</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940674"><span class="hs-identifier hs-var">lo</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="GHC.Cmm.Switch.html#minJumpTableOffset"><span class="hs-identifier hs-var">minJumpTableOffset</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">0</span></span><span>  </span><span class="hs-comment">-- See Note [Jump Table Offset]</span><span>
</span><span id="line-173"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940674"><span class="hs-identifier hs-var">lo</span></a></span><span>
</span><span id="line-174"></span><span>
</span><span id="line-175"></span><span class="hs-comment">-- Note [Jump Table Offset]</span><span>
</span><span id="line-176"></span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-177"></span><span class="hs-comment">--</span><span>
</span><span id="line-178"></span><span class="hs-comment">-- Usually, the code for a jump table starting at x will first subtract x from</span><span>
</span><span id="line-179"></span><span class="hs-comment">-- the value, to avoid a large amount of empty entries. But if x is very small,</span><span>
</span><span id="line-180"></span><span class="hs-comment">-- the extra entries are no worse than the subtraction in terms of code size, and</span><span>
</span><span id="line-181"></span><span class="hs-comment">-- not having to do the subtraction is quicker.</span><span>
</span><span id="line-182"></span><span class="hs-comment">--</span><span>
</span><span id="line-183"></span><span class="hs-comment">-- I.e. instead of</span><span>
</span><span id="line-184"></span><span class="hs-comment">--     _u20N:</span><span>
</span><span id="line-185"></span><span class="hs-comment">--             leaq -1(%r14),%rax</span><span>
</span><span id="line-186"></span><span class="hs-comment">--             jmp *_n20R(,%rax,8)</span><span>
</span><span id="line-187"></span><span class="hs-comment">--     _n20R:</span><span>
</span><span id="line-188"></span><span class="hs-comment">--             .quad   _c20p</span><span>
</span><span id="line-189"></span><span class="hs-comment">--             .quad   _c20q</span><span>
</span><span id="line-190"></span><span class="hs-comment">-- do</span><span>
</span><span id="line-191"></span><span class="hs-comment">--     _u20N:</span><span>
</span><span id="line-192"></span><span class="hs-comment">--             jmp *_n20Q(,%r14,8)</span><span>
</span><span id="line-193"></span><span class="hs-comment">--</span><span>
</span><span id="line-194"></span><span class="hs-comment">--     _n20Q:</span><span>
</span><span id="line-195"></span><span class="hs-comment">--             .quad   0</span><span>
</span><span id="line-196"></span><span class="hs-comment">--             .quad   _c20p</span><span>
</span><span id="line-197"></span><span class="hs-comment">--             .quad   _c20q</span><span>
</span><span id="line-198"></span><span class="hs-comment">--             .quad   _c20r</span><span>
</span><span id="line-199"></span><span>
</span><span id="line-200"></span><span class="hs-comment">-- | The list of all labels occurring in the SwitchTargets value.</span><span>
</span><span id="line-201"></span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsToList"><span class="hs-identifier hs-type">switchTargetsToList</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-202"></span><span id="switchTargetsToList"><span class="annot"><span class="annottext">switchTargetsToList :: SwitchTargets -&gt; [Label]
</span><a href="GHC.Cmm.Switch.html#switchTargetsToList"><span class="hs-identifier hs-var hs-var">switchTargetsToList</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680940662"><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940662"><span class="hs-identifier hs-var">mbdef</span></a></span></span><span> </span><span id="local-6989586621680940661"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940661"><span class="hs-identifier hs-var">branches</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-203"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe Label -&gt; [Label]
forall a. Maybe a -&gt; [a]
</span><a href="../../base/src/Data.Maybe.html#maybeToList"><span class="hs-identifier hs-var">maybeToList</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940662"><span class="hs-identifier hs-var">mbdef</span></a></span><span> </span><span class="annot"><span class="annottext">[Label] -&gt; [Label] -&gt; [Label]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label -&gt; [Label]
forall k a. Map k a -&gt; [a]
</span><a href="../../containers/src/Data.Map.Internal.html#elems"><span class="hs-identifier hs-var">M.elems</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940661"><span class="hs-identifier hs-var">branches</span></a></span><span>
</span><span id="line-204"></span><span>
</span><span id="line-205"></span><span class="hs-comment">-- | Groups cases with equal targets, suitable for pretty-printing to a</span><span>
</span><span id="line-206"></span><span class="hs-comment">-- c-like switch statement with fall-through semantics.</span><span>
</span><span id="line-207"></span><span class="annot"><a href="GHC.Cmm.Switch.html#switchTargetsFallThrough"><span class="hs-identifier hs-type">switchTargetsFallThrough</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-208"></span><span id="switchTargetsFallThrough"><span class="annot"><span class="annottext">switchTargetsFallThrough :: SwitchTargets -&gt; ([([Integer], Label)], Maybe Label)
</span><a href="GHC.Cmm.Switch.html#switchTargetsFallThrough"><span class="hs-identifier hs-var hs-var">switchTargetsFallThrough</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680940658"><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940658"><span class="hs-identifier hs-var">mbdef</span></a></span></span><span> </span><span id="local-6989586621680940657"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940657"><span class="hs-identifier hs-var">branches</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[([Integer], Label)]
</span><a href="#local-6989586621680940656"><span class="hs-identifier hs-var">groups</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940658"><span class="hs-identifier hs-var">mbdef</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-209"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-210"></span><span>    </span><span id="local-6989586621680940656"><span class="annot"><span class="annottext">groups :: [([Integer], Label)]
</span><a href="#local-6989586621680940656"><span class="hs-identifier hs-var hs-var">groups</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">([(Integer, Label)] -&gt; ([Integer], Label))
-&gt; [[(Integer, Label)]] -&gt; [([Integer], Label)]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621680940655"><span class="annot"><span class="annottext">[(Integer, Label)]
</span><a href="#local-6989586621680940655"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">((Integer, Label) -&gt; Integer) -&gt; [(Integer, Label)] -&gt; [Integer]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">(Integer, Label) -&gt; Integer
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span> </span><span class="annot"><span class="annottext">[(Integer, Label)]
</span><a href="#local-6989586621680940655"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">(Integer, Label) -&gt; Label
forall a b. (a, b) -&gt; b
</span><a href="../../base/src/Data.Tuple.html#snd"><span class="hs-identifier hs-var">snd</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[(Integer, Label)] -&gt; (Integer, Label)
forall a. [a] -&gt; a
</span><a href="../../base/src/GHC.List.html#head"><span class="hs-identifier hs-var">head</span></a></span><span> </span><span class="annot"><span class="annottext">[(Integer, Label)]
</span><a href="#local-6989586621680940655"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">([[(Integer, Label)]] -&gt; [([Integer], Label)])
-&gt; [[(Integer, Label)]] -&gt; [([Integer], Label)]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-211"></span><span>             </span><span class="annot"><span class="annottext">((Integer, Label) -&gt; (Integer, Label) -&gt; Bool)
-&gt; [(Integer, Label)] -&gt; [[(Integer, Label)]]
forall a. (a -&gt; a -&gt; Bool) -&gt; [a] -&gt; [[a]]
</span><a href="../../base/src/Data.OldList.html#groupBy"><span class="hs-identifier hs-var">groupBy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Label -&gt; Label -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">(==)</span></span><span> </span><span class="annot"><span class="annottext">(Label -&gt; Label -&gt; Bool)
-&gt; ((Integer, Label) -&gt; Label)
-&gt; (Integer, Label)
-&gt; (Integer, Label)
-&gt; Bool
forall b c a. (b -&gt; b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; a -&gt; c
</span><a href="../../base/src/Data.Function.html#on"><span class="hs-operator hs-var">`on`</span></a></span><span> </span><span class="annot"><span class="annottext">(Integer, Label) -&gt; Label
forall a b. (a, b) -&gt; b
</span><a href="../../base/src/Data.Tuple.html#snd"><span class="hs-identifier hs-var">snd</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">([(Integer, Label)] -&gt; [[(Integer, Label)]])
-&gt; [(Integer, Label)] -&gt; [[(Integer, Label)]]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-212"></span><span>             </span><span class="annot"><span class="annottext">Map Integer Label -&gt; [(Integer, Label)]
forall k a. Map k a -&gt; [(k, a)]
</span><a href="../../containers/src/Data.Map.Internal.html#toList"><span class="hs-identifier hs-var">M.toList</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940657"><span class="hs-identifier hs-var">branches</span></a></span><span>
</span><span id="line-213"></span><span>
</span><span id="line-214"></span><span class="hs-comment">-- | Custom equality helper, needed for &quot;GHC.Cmm.CommonBlockElim&quot;</span><span>
</span><span id="line-215"></span><span class="annot"><a href="GHC.Cmm.Switch.html#eqSwitchTargetWith"><span class="hs-identifier hs-type">eqSwitchTargetWith</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-216"></span><span id="eqSwitchTargetWith"><span class="annot"><span class="annottext">eqSwitchTargetWith :: (Label -&gt; Label -&gt; Bool) -&gt; SwitchTargets -&gt; SwitchTargets -&gt; Bool
</span><a href="GHC.Cmm.Switch.html#eqSwitchTargetWith"><span class="hs-identifier hs-var hs-var">eqSwitchTargetWith</span></a></span></span><span> </span><span id="local-6989586621680940653"><span class="annot"><span class="annottext">Label -&gt; Label -&gt; Bool
</span><a href="#local-6989586621680940653"><span class="hs-identifier hs-var">eq</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span id="local-6989586621680940652"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940652"><span class="hs-identifier hs-var">signed1</span></a></span></span><span> </span><span id="local-6989586621680940651"><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940651"><span class="hs-identifier hs-var">range1</span></a></span></span><span> </span><span id="local-6989586621680940650"><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940650"><span class="hs-identifier hs-var">mbdef1</span></a></span></span><span> </span><span id="local-6989586621680940649"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940649"><span class="hs-identifier hs-var">ids1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span id="local-6989586621680940648"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940648"><span class="hs-identifier hs-var">signed2</span></a></span></span><span> </span><span id="local-6989586621680940647"><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940647"><span class="hs-identifier hs-var">range2</span></a></span></span><span> </span><span id="local-6989586621680940646"><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940646"><span class="hs-identifier hs-var">mbdef2</span></a></span></span><span> </span><span id="local-6989586621680940645"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940645"><span class="hs-identifier hs-var">ids2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-217"></span><span>    </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940652"><span class="hs-identifier hs-var">signed1</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940648"><span class="hs-identifier hs-var">signed2</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940651"><span class="hs-identifier hs-var">range1</span></a></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer) -&gt; (Integer, Integer) -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940647"><span class="hs-identifier hs-var">range2</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Maybe Label -&gt; Maybe Label -&gt; Bool
</span><a href="#local-6989586621680940644"><span class="hs-identifier hs-var">goMB</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940650"><span class="hs-identifier hs-var">mbdef1</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940646"><span class="hs-identifier hs-var">mbdef2</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">[(Integer, Label)] -&gt; [(Integer, Label)] -&gt; Bool
</span><a href="#local-6989586621680940643"><span class="hs-identifier hs-var">goList</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer Label -&gt; [(Integer, Label)]
forall k a. Map k a -&gt; [(k, a)]
</span><a href="../../containers/src/Data.Map.Internal.html#toList"><span class="hs-identifier hs-var">M.toList</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940649"><span class="hs-identifier hs-var">ids1</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer Label -&gt; [(Integer, Label)]
forall k a. Map k a -&gt; [(k, a)]
</span><a href="../../containers/src/Data.Map.Internal.html#toList"><span class="hs-identifier hs-var">M.toList</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940645"><span class="hs-identifier hs-var">ids2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-218"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-219"></span><span>    </span><span id="local-6989586621680940644"><span class="annot"><span class="annottext">goMB :: Maybe Label -&gt; Maybe Label -&gt; Bool
</span><a href="#local-6989586621680940644"><span class="hs-identifier hs-var hs-var">goMB</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-220"></span><span>    </span><span class="annot"><a href="#local-6989586621680940644"><span class="hs-identifier hs-var">goMB</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680940642"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940642"><span class="hs-identifier hs-var">l1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680940641"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940641"><span class="hs-identifier hs-var">l2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940642"><span class="hs-identifier hs-var">l1</span></a></span><span> </span><span class="annot"><span class="annottext">Label -&gt; Label -&gt; Bool
</span><a href="#local-6989586621680940653"><span class="hs-operator hs-var">`eq`</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940641"><span class="hs-identifier hs-var">l2</span></a></span><span>
</span><span id="line-221"></span><span>    </span><span class="annot"><a href="#local-6989586621680940644"><span class="hs-identifier hs-var">goMB</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-222"></span><span>    </span><span id="local-6989586621680940643"><span class="annot"><span class="annottext">goList :: [(Integer, Label)] -&gt; [(Integer, Label)] -&gt; Bool
</span><a href="#local-6989586621680940643"><span class="hs-identifier hs-var hs-var">goList</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-223"></span><span>    </span><span class="annot"><a href="#local-6989586621680940643"><span class="hs-identifier hs-var">goList</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span id="local-6989586621680940640"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940640"><span class="hs-identifier hs-var">i1</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940639"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940639"><span class="hs-identifier hs-var">l1</span></a></span></span><span class="hs-special">)</span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680940638"><span class="annot"><span class="annottext">[(Integer, Label)]
</span><a href="#local-6989586621680940638"><span class="hs-identifier hs-var">ls1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span id="local-6989586621680940637"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940637"><span class="hs-identifier hs-var">i2</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940636"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940636"><span class="hs-identifier hs-var">l2</span></a></span></span><span class="hs-special">)</span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680940635"><span class="annot"><span class="annottext">[(Integer, Label)]
</span><a href="#local-6989586621680940635"><span class="hs-identifier hs-var">ls2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940640"><span class="hs-identifier hs-var">i1</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940637"><span class="hs-identifier hs-var">i2</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940639"><span class="hs-identifier hs-var">l1</span></a></span><span> </span><span class="annot"><span class="annottext">Label -&gt; Label -&gt; Bool
</span><a href="#local-6989586621680940653"><span class="hs-operator hs-var">`eq`</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940636"><span class="hs-identifier hs-var">l2</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">[(Integer, Label)] -&gt; [(Integer, Label)] -&gt; Bool
</span><a href="#local-6989586621680940643"><span class="hs-identifier hs-var">goList</span></a></span><span> </span><span class="annot"><span class="annottext">[(Integer, Label)]
</span><a href="#local-6989586621680940638"><span class="hs-identifier hs-var">ls1</span></a></span><span> </span><span class="annot"><span class="annottext">[(Integer, Label)]
</span><a href="#local-6989586621680940635"><span class="hs-identifier hs-var">ls2</span></a></span><span>
</span><span id="line-224"></span><span>    </span><span class="annot"><a href="#local-6989586621680940643"><span class="hs-identifier hs-var">goList</span></a></span><span> </span><span class="annot"><span class="annottext">[(Integer, Label)]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[(Integer, Label)]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-225"></span><span>
</span><span id="line-226"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-227"></span><span class="hs-comment">-- Code generation for Switches</span><span>
</span><span id="line-228"></span><span>
</span><span id="line-229"></span><span>
</span><span id="line-230"></span><span class="hs-comment">-- | A SwitchPlan abstractly describes how a Switch statement ought to be</span><span>
</span><span id="line-231"></span><span class="hs-comment">-- implemented. See Note [createSwitchPlan]</span><span>
</span><span id="line-232"></span><span class="hs-keyword">data</span><span> </span><span id="SwitchPlan"><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchPlan"><span class="hs-identifier hs-var">SwitchPlan</span></a></span></span><span>
</span><span id="line-233"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span id="Unconditionally"><span class="annot"><a href="GHC.Cmm.Switch.html#Unconditionally"><span class="hs-identifier hs-var">Unconditionally</span></a></span></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span>
</span><span id="line-234"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span id="IfEqual"><span class="annot"><a href="GHC.Cmm.Switch.html#IfEqual"><span class="hs-identifier hs-var">IfEqual</span></a></span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchPlan"><span class="hs-identifier hs-type">SwitchPlan</span></a></span><span>
</span><span id="line-235"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span id="IfLT"><span class="annot"><a href="GHC.Cmm.Switch.html#IfLT"><span class="hs-identifier hs-var">IfLT</span></a></span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchPlan"><span class="hs-identifier hs-type">SwitchPlan</span></a></span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchPlan"><span class="hs-identifier hs-type">SwitchPlan</span></a></span><span>
</span><span id="line-236"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span id="JumpTable"><span class="annot"><a href="GHC.Cmm.Switch.html#JumpTable"><span class="hs-identifier hs-var">JumpTable</span></a></span></span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span>
</span><span id="line-237"></span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span id="local-6989586621680940612"><span id="local-6989586621680940614"><span id="local-6989586621680940629"><span class="annot"><span class="annottext">Int -&gt; SwitchPlan -&gt; ShowS
[SwitchPlan] -&gt; ShowS
SwitchPlan -&gt; String
(Int -&gt; SwitchPlan -&gt; ShowS)
-&gt; (SwitchPlan -&gt; String)
-&gt; ([SwitchPlan] -&gt; ShowS)
-&gt; Show SwitchPlan
forall a.
(Int -&gt; a -&gt; ShowS) -&gt; (a -&gt; String) -&gt; ([a] -&gt; ShowS) -&gt; Show a
showList :: [SwitchPlan] -&gt; ShowS
$cshowList :: [SwitchPlan] -&gt; ShowS
show :: SwitchPlan -&gt; String
$cshow :: SwitchPlan -&gt; String
showsPrec :: Int -&gt; SwitchPlan -&gt; ShowS
$cshowsPrec :: Int -&gt; SwitchPlan -&gt; ShowS
</span><a href="../../base/src/GHC.Show.html#Show"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Show</span></a></span></span></span></span><span>
</span><span id="line-238"></span><span class="hs-comment">--</span><span>
</span><span id="line-239"></span><span class="hs-comment">-- Note [createSwitchPlan]</span><span>
</span><span id="line-240"></span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-241"></span><span class="hs-comment">--</span><span>
</span><span id="line-242"></span><span class="hs-comment">-- A SwitchPlan describes how a Switch statement is to be broken down into</span><span>
</span><span id="line-243"></span><span class="hs-comment">-- smaller pieces suitable for code generation.</span><span>
</span><span id="line-244"></span><span class="hs-comment">--</span><span>
</span><span id="line-245"></span><span class="hs-comment">-- createSwitchPlan creates such a switch plan, in these steps:</span><span>
</span><span id="line-246"></span><span class="hs-comment">--  1. It splits the switch statement at segments of non-default values that</span><span>
</span><span id="line-247"></span><span class="hs-comment">--     are too large. See splitAtHoles and Note [Magic Constants in GHC.Cmm.Switch]</span><span>
</span><span id="line-248"></span><span class="hs-comment">--  2. Too small jump tables should be avoided, so we break up smaller pieces</span><span>
</span><span id="line-249"></span><span class="hs-comment">--     in breakTooSmall.</span><span>
</span><span id="line-250"></span><span class="hs-comment">--  3. We fill in the segments between those pieces with a jump to the default</span><span>
</span><span id="line-251"></span><span class="hs-comment">--     label (if there is one), returning a SeparatedList in mkFlatSwitchPlan</span><span>
</span><span id="line-252"></span><span class="hs-comment">--  4. We find and replace two less-than branches by a single equal-to-test in</span><span>
</span><span id="line-253"></span><span class="hs-comment">--     findSingleValues</span><span>
</span><span id="line-254"></span><span class="hs-comment">--  5. The thus collected pieces are assembled to a balanced binary tree.</span><span>
</span><span id="line-255"></span><span>
</span><span id="line-256"></span><span class="hs-comment">{-
  Note [Two alts + default]
  ~~~~~~~~~~~~~~~~~~~~~~~~~

Discussion and a bit more info at #14644

When dealing with a switch of the form:
switch(e) {
  case 1: goto l1;
  case 3000: goto l2;
  default: goto ldef;
}

If we treat it as a sparse jump table we would generate:

if (e &gt; 3000) //Check if value is outside of the jump table.
    goto ldef;
else {
    if (e &lt; 3000) { //Compare to upper value
        if(e != 1) //Compare to remaining value
            goto ldef;
          else
            goto l2;
    }
    else
        goto l1;
}

Instead we special case this to :

if (e==1) goto l1;
else if (e==3000) goto l2;
else goto l3;

This means we have:
* Less comparisons for: 1,&lt;3000
* Unchanged for 3000
* One more for &gt;3000

This improves code in a few ways:
* One comparison less means smaller code which helps with cache.
* It exchanges a taken jump for two jumps no taken in the &gt;range case.
  Jumps not taken are cheaper (See Agner guides) making this about as fast.
* For all other cases the first range check is removed making it faster.

The end result is that the change is not measurably slower for the case
&gt;3000 and faster for the other cases.

This makes running this kind of match in an inner loop cheaper by 10-20%
depending on the data.
In nofib this improves wheel-sieve1 by 4-9% depending on problem
size.

We could also add a second conditional jump after the comparison to
keep the range check like this:
    cmp 3000, rArgument
    jg &lt;default&gt;
    je &lt;branch 2&gt;
While this is fairly cheap it made no big difference for the &gt;3000 case
and slowed down all other cases making it not worthwhile.
-}</span><span>
</span><span id="line-317"></span><span>
</span><span id="line-318"></span><span>
</span><span id="line-319"></span><span class="hs-comment">-- | Does the target support switch out of the box? Then leave this to the</span><span>
</span><span id="line-320"></span><span class="hs-comment">-- target!</span><span>
</span><span id="line-321"></span><span class="annot"><a href="GHC.Cmm.Switch.html#targetSupportsSwitch"><span class="hs-identifier hs-type">targetSupportsSwitch</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#HscTarget"><span class="hs-identifier hs-type">HscTarget</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-322"></span><span id="targetSupportsSwitch"><span class="annot"><span class="annottext">targetSupportsSwitch :: HscTarget -&gt; Bool
</span><a href="GHC.Cmm.Switch.html#targetSupportsSwitch"><span class="hs-identifier hs-var hs-var">targetSupportsSwitch</span></a></span></span><span> </span><span class="annot"><span class="annottext">HscTarget
</span><a href="GHC.Driver.Session.html#HscC"><span class="hs-identifier hs-var">HscC</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-323"></span><span class="annot"><a href="GHC.Cmm.Switch.html#targetSupportsSwitch"><span class="hs-identifier hs-var">targetSupportsSwitch</span></a></span><span> </span><span class="annot"><span class="annottext">HscTarget
</span><a href="GHC.Driver.Session.html#HscLlvm"><span class="hs-identifier hs-var">HscLlvm</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-324"></span><span class="annot"><a href="GHC.Cmm.Switch.html#targetSupportsSwitch"><span class="hs-identifier hs-var">targetSupportsSwitch</span></a></span><span> </span><span class="annot"><span class="annottext">HscTarget
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-325"></span><span>
</span><span id="line-326"></span><span class="hs-comment">-- | This function creates a SwitchPlan from a SwitchTargets value, breaking it</span><span>
</span><span id="line-327"></span><span class="hs-comment">-- down into smaller pieces suitable for code generation.</span><span>
</span><span id="line-328"></span><span class="annot"><a href="GHC.Cmm.Switch.html#createSwitchPlan"><span class="hs-identifier hs-type">createSwitchPlan</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchPlan"><span class="hs-identifier hs-type">SwitchPlan</span></a></span><span>
</span><span id="line-329"></span><span class="hs-comment">-- Lets do the common case of a singleton map quickly and efficiently (#10677)</span><span>
</span><span id="line-330"></span><span id="createSwitchPlan"><span class="annot"><span class="annottext">createSwitchPlan :: SwitchTargets -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#createSwitchPlan"><span class="hs-identifier hs-var hs-var">createSwitchPlan</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span id="local-6989586621680940609"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940609"><span class="hs-identifier hs-var">_signed</span></a></span></span><span> </span><span id="local-6989586621680940608"><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940608"><span class="hs-identifier hs-var">_range</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680940607"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940607"><span class="hs-identifier hs-var">defLabel</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680940606"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940606"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-331"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span id="local-6989586621680940605"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940605"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680940604"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940604"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Map Integer Label -&gt; [(Integer, Label)]
forall k a. Map k a -&gt; [(k, a)]
</span><a href="../../containers/src/Data.Map.Internal.html#toList"><span class="hs-identifier hs-var">M.toList</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940606"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-332"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Label -&gt; SwitchPlan -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#IfEqual"><span class="hs-identifier hs-var">IfEqual</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940605"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940604"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Label -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#Unconditionally"><span class="hs-identifier hs-var">Unconditionally</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940607"><span class="hs-identifier hs-var">defLabel</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-333"></span><span class="hs-comment">-- And another common case, matching &quot;booleans&quot;</span><span>
</span><span id="line-334"></span><span class="annot"><a href="GHC.Cmm.Switch.html#createSwitchPlan"><span class="hs-identifier hs-var">createSwitchPlan</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span id="local-6989586621680940603"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940603"><span class="hs-identifier hs-var">_signed</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940602"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940602"><span class="hs-identifier hs-var">lo</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940601"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940601"><span class="hs-identifier hs-var">hi</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span id="local-6989586621680940600"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940600"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-335"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span id="local-6989586621680940599"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940599"><span class="hs-identifier hs-var">x1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680940598"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940598"><span class="hs-identifier hs-var">l1</span></a></span></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940597"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940597"><span class="hs-identifier hs-var">_x2</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940596"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940596"><span class="hs-identifier hs-var">l2</span></a></span></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Map Integer Label -&gt; [(Integer, Label)]
forall k a. Map k a -&gt; [(k, a)]
</span><a href="../../containers/src/Data.Map.Internal.html#toAscList"><span class="hs-identifier hs-var">M.toAscList</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940600"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-336"></span><span>    </span><span class="hs-comment">--Checking If |range| = 2 is enough if we have two unique literals</span><span>
</span><span id="line-337"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940601"><span class="hs-identifier hs-var">hi</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Integer
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940602"><span class="hs-identifier hs-var">lo</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">1</span></span><span>
</span><span id="line-338"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Label -&gt; SwitchPlan -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#IfEqual"><span class="hs-identifier hs-var">IfEqual</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940599"><span class="hs-identifier hs-var">x1</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940598"><span class="hs-identifier hs-var">l1</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Label -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#Unconditionally"><span class="hs-identifier hs-var">Unconditionally</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940596"><span class="hs-identifier hs-var">l2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-339"></span><span class="hs-comment">-- See Note [Two alts + default]</span><span>
</span><span id="line-340"></span><span class="annot"><a href="GHC.Cmm.Switch.html#createSwitchPlan"><span class="hs-identifier hs-var">createSwitchPlan</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span id="local-6989586621680940594"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940594"><span class="hs-identifier hs-var">_signed</span></a></span></span><span> </span><span id="local-6989586621680940593"><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940593"><span class="hs-identifier hs-var">_range</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680940592"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940592"><span class="hs-identifier hs-var">defLabel</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680940591"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940591"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-341"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span id="local-6989586621680940590"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940590"><span class="hs-identifier hs-var">x1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680940589"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940589"><span class="hs-identifier hs-var">l1</span></a></span></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940588"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940588"><span class="hs-identifier hs-var">x2</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940587"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940587"><span class="hs-identifier hs-var">l2</span></a></span></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Map Integer Label -&gt; [(Integer, Label)]
forall k a. Map k a -&gt; [(k, a)]
</span><a href="../../containers/src/Data.Map.Internal.html#toAscList"><span class="hs-identifier hs-var">M.toAscList</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940591"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-342"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Label -&gt; SwitchPlan -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#IfEqual"><span class="hs-identifier hs-var">IfEqual</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940590"><span class="hs-identifier hs-var">x1</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940589"><span class="hs-identifier hs-var">l1</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer -&gt; Label -&gt; SwitchPlan -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#IfEqual"><span class="hs-identifier hs-var">IfEqual</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940588"><span class="hs-identifier hs-var">x2</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940587"><span class="hs-identifier hs-var">l2</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Label -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#Unconditionally"><span class="hs-identifier hs-var">Unconditionally</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940592"><span class="hs-identifier hs-var">defLabel</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-343"></span><span class="annot"><a href="GHC.Cmm.Switch.html#createSwitchPlan"><span class="hs-identifier hs-var">createSwitchPlan</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchTargets"><span class="hs-identifier hs-type">SwitchTargets</span></a></span><span> </span><span id="local-6989586621680940586"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940586"><span class="hs-identifier hs-var">signed</span></a></span></span><span> </span><span id="local-6989586621680940585"><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940585"><span class="hs-identifier hs-var">range</span></a></span></span><span> </span><span id="local-6989586621680940584"><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940584"><span class="hs-identifier hs-var">mbdef</span></a></span></span><span> </span><span id="local-6989586621680940583"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940583"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-344"></span><span>    </span><span class="hs-comment">-- pprTrace &quot;createSwitchPlan&quot; (text (show ids) $$ text (show (range,m)) $$ text (show pieces) $$ text (show flatPlan) $$ text (show plan)) $</span><span>
</span><span id="line-345"></span><span>    </span><span class="annot"><span class="annottext">SwitchPlan
</span><a href="#local-6989586621680940582"><span class="hs-identifier hs-var">plan</span></a></span><span>
</span><span id="line-346"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-347"></span><span>    </span><span id="local-6989586621680940581"><span class="annot"><span class="annottext">pieces :: [Map Integer Label]
</span><a href="#local-6989586621680940581"><span class="hs-identifier hs-var hs-var">pieces</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Map Integer Label -&gt; [Map Integer Label])
-&gt; [Map Integer Label] -&gt; [Map Integer Label]
forall (t :: * -&gt; *) a b. Foldable t =&gt; (a -&gt; [b]) -&gt; t a -&gt; [b]
</span><a href="../../base/src/Data.Foldable.html#concatMap"><span class="hs-identifier hs-var">concatMap</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label -&gt; [Map Integer Label]
forall a. Map Integer a -&gt; [Map Integer a]
</span><a href="GHC.Cmm.Switch.html#breakTooSmall"><span class="hs-identifier hs-var">breakTooSmall</span></a></span><span> </span><span class="annot"><span class="annottext">([Map Integer Label] -&gt; [Map Integer Label])
-&gt; [Map Integer Label] -&gt; [Map Integer Label]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Map Integer Label -&gt; [Map Integer Label]
forall a. Integer -&gt; Map Integer a -&gt; [Map Integer a]
</span><a href="GHC.Cmm.Switch.html#splitAtHoles"><span class="hs-identifier hs-var">splitAtHoles</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="GHC.Cmm.Switch.html#maxJumpTableHole"><span class="hs-identifier hs-var">maxJumpTableHole</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940583"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-348"></span><span>    </span><span id="local-6989586621680940577"><span class="annot"><span class="annottext">flatPlan :: FlatSwitchPlan
</span><a href="#local-6989586621680940577"><span class="hs-identifier hs-var hs-var">flatPlan</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FlatSwitchPlan -&gt; FlatSwitchPlan
</span><a href="GHC.Cmm.Switch.html#findSingleValues"><span class="hs-identifier hs-var">findSingleValues</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatSwitchPlan -&gt; FlatSwitchPlan)
-&gt; FlatSwitchPlan -&gt; FlatSwitchPlan
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
-&gt; Maybe Label
-&gt; (Integer, Integer)
-&gt; [Map Integer Label]
-&gt; FlatSwitchPlan
</span><a href="GHC.Cmm.Switch.html#mkFlatSwitchPlan"><span class="hs-identifier hs-var">mkFlatSwitchPlan</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940586"><span class="hs-identifier hs-var">signed</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940584"><span class="hs-identifier hs-var">mbdef</span></a></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940585"><span class="hs-identifier hs-var">range</span></a></span><span> </span><span class="annot"><span class="annottext">[Map Integer Label]
</span><a href="#local-6989586621680940581"><span class="hs-identifier hs-var">pieces</span></a></span><span>
</span><span id="line-349"></span><span>    </span><span id="local-6989586621680940582"><span class="annot"><span class="annottext">plan :: SwitchPlan
</span><a href="#local-6989586621680940582"><span class="hs-identifier hs-var hs-var">plan</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; FlatSwitchPlan -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#buildTree"><span class="hs-identifier hs-var">buildTree</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940586"><span class="hs-identifier hs-var">signed</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatSwitchPlan -&gt; SwitchPlan) -&gt; FlatSwitchPlan -&gt; SwitchPlan
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">FlatSwitchPlan
</span><a href="#local-6989586621680940577"><span class="hs-identifier hs-var">flatPlan</span></a></span><span>
</span><span id="line-350"></span><span>
</span><span id="line-351"></span><span>
</span><span id="line-352"></span><span class="hs-comment">---</span><span>
</span><span id="line-353"></span><span class="hs-comment">--- Step 1: Splitting at large holes</span><span>
</span><span id="line-354"></span><span class="hs-comment">---</span><span>
</span><span id="line-355"></span><span id="local-6989586621680940851"><span class="annot"><a href="GHC.Cmm.Switch.html#splitAtHoles"><span class="hs-identifier hs-type">splitAtHoles</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../containers/src/Data.Map.Internal.html#Map"><span class="hs-identifier hs-type">M.Map</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="#local-6989586621680940851"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../containers/src/Data.Map.Internal.html#Map"><span class="hs-identifier hs-type">M.Map</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="#local-6989586621680940851"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-356"></span><span id="splitAtHoles"><span class="annot"><span class="annottext">splitAtHoles :: forall a. Integer -&gt; Map Integer a -&gt; [Map Integer a]
</span><a href="GHC.Cmm.Switch.html#splitAtHoles"><span class="hs-identifier hs-var hs-var">splitAtHoles</span></a></span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-identifier">_</span></span><span>        </span><span id="local-6989586621680940571"><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940571"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Map Integer a -&gt; Bool
forall k a. Map k a -&gt; Bool
</span><a href="../../containers/src/Data.Map.Internal.html#null"><span class="hs-identifier hs-var">M.null</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940571"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-357"></span><span class="annot"><a href="GHC.Cmm.Switch.html#splitAtHoles"><span class="hs-identifier hs-var">splitAtHoles</span></a></span><span> </span><span id="local-6989586621680940569"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940569"><span class="hs-identifier hs-var">holeSize</span></a></span></span><span> </span><span id="local-6989586621680940568"><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940568"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((Integer, Integer) -&gt; Map Integer a)
-&gt; [(Integer, Integer)] -&gt; [Map Integer a]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621680940567"><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940567"><span class="hs-identifier hs-var">range</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(Integer, Integer) -&gt; Map Integer a -&gt; Map Integer a
forall b. (Integer, Integer) -&gt; Map Integer b -&gt; Map Integer b
</span><a href="GHC.Cmm.Switch.html#restrictMap"><span class="hs-identifier hs-var">restrictMap</span></a></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940567"><span class="hs-identifier hs-var">range</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940568"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(Integer, Integer)]
</span><a href="#local-6989586621680940566"><span class="hs-identifier hs-var">nonHoles</span></a></span><span>
</span><span id="line-358"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-359"></span><span>    </span><span id="local-6989586621680940565"><span class="annot"><span class="annottext">holes :: [(Integer, Integer)]
</span><a href="#local-6989586621680940565"><span class="hs-identifier hs-var hs-var">holes</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((Integer, Integer) -&gt; Bool)
-&gt; [(Integer, Integer)] -&gt; [(Integer, Integer)]
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#filter"><span class="hs-identifier hs-var">filter</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-special">(</span><span id="local-6989586621680940564"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940564"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940563"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940563"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940563"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Integer
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940564"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940569"><span class="hs-identifier hs-var">holeSize</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">([(Integer, Integer)] -&gt; [(Integer, Integer)])
-&gt; [(Integer, Integer)] -&gt; [(Integer, Integer)]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[Integer] -&gt; [Integer] -&gt; [(Integer, Integer)]
forall a b. [a] -&gt; [b] -&gt; [(a, b)]
</span><a href="../../base/src/GHC.List.html#zip"><span class="hs-identifier hs-var">zip</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer a -&gt; [Integer]
forall k a. Map k a -&gt; [k]
</span><a href="../../containers/src/Data.Map.Internal.html#keys"><span class="hs-identifier hs-var">M.keys</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940568"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Integer] -&gt; [Integer]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#tail"><span class="hs-identifier hs-var">tail</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer a -&gt; [Integer]
forall k a. Map k a -&gt; [k]
</span><a href="../../containers/src/Data.Map.Internal.html#keys"><span class="hs-identifier hs-var">M.keys</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940568"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-360"></span><span>    </span><span id="local-6989586621680940566"><span class="annot"><span class="annottext">nonHoles :: [(Integer, Integer)]
</span><a href="#local-6989586621680940566"><span class="hs-identifier hs-var hs-var">nonHoles</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Integer -&gt; [(Integer, Integer)] -&gt; Integer -&gt; [(Integer, Integer)]
forall a. a -&gt; [(a, a)] -&gt; a -&gt; [(a, a)]
</span><a href="GHC.Cmm.Switch.html#reassocTuples"><span class="hs-identifier hs-var">reassocTuples</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940558"><span class="hs-identifier hs-var">lo</span></a></span><span> </span><span class="annot"><span class="annottext">[(Integer, Integer)]
</span><a href="#local-6989586621680940565"><span class="hs-identifier hs-var">holes</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940557"><span class="hs-identifier hs-var">hi</span></a></span><span>
</span><span id="line-361"></span><span>
</span><span id="line-362"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680940558"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940558"><span class="hs-identifier hs-var">lo</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Map Integer a -&gt; (Integer, a)
forall k a. Map k a -&gt; (k, a)
</span><a href="../../containers/src/Data.Map.Internal.html#findMin"><span class="hs-identifier hs-var">M.findMin</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940568"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-363"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680940557"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940557"><span class="hs-identifier hs-var">hi</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Map Integer a -&gt; (Integer, a)
forall k a. Map k a -&gt; (k, a)
</span><a href="../../containers/src/Data.Map.Internal.html#findMax"><span class="hs-identifier hs-var">M.findMax</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940568"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-364"></span><span>
</span><span id="line-365"></span><span class="hs-comment">---</span><span>
</span><span id="line-366"></span><span class="hs-comment">--- Step 2: Avoid small jump tables</span><span>
</span><span id="line-367"></span><span class="hs-comment">---</span><span>
</span><span id="line-368"></span><span class="hs-comment">-- We do not want jump tables below a certain size. This breaks them up</span><span>
</span><span id="line-369"></span><span class="hs-comment">-- (into singleton maps, for now).</span><span>
</span><span id="line-370"></span><span id="local-6989586621680940852"><span class="annot"><a href="GHC.Cmm.Switch.html#breakTooSmall"><span class="hs-identifier hs-type">breakTooSmall</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../containers/src/Data.Map.Internal.html#Map"><span class="hs-identifier hs-type">M.Map</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="#local-6989586621680940852"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../containers/src/Data.Map.Internal.html#Map"><span class="hs-identifier hs-type">M.Map</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="#local-6989586621680940852"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-371"></span><span id="breakTooSmall"><span class="annot"><span class="annottext">breakTooSmall :: forall a. Map Integer a -&gt; [Map Integer a]
</span><a href="GHC.Cmm.Switch.html#breakTooSmall"><span class="hs-identifier hs-var hs-var">breakTooSmall</span></a></span></span><span> </span><span id="local-6989586621680940553"><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940553"><span class="hs-identifier hs-var">m</span></a></span></span><span>
</span><span id="line-372"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Map Integer a -&gt; Int
forall k a. Map k a -&gt; Int
</span><a href="../../containers/src/Data.Map.Internal.html#size"><span class="hs-identifier hs-var">M.size</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940553"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.Cmm.Switch.html#minJumpTableSize"><span class="hs-identifier hs-var">minJumpTableSize</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940553"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-373"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                   </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Integer -&gt; a -&gt; Map Integer a
forall k a. k -&gt; a -&gt; Map k a
</span><a href="../../containers/src/Data.Map.Internal.html#singleton"><span class="hs-identifier hs-var">M.singleton</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940551"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940550"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940551"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940551"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940550"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940550"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Map Integer a -&gt; [(Integer, a)]
forall k a. Map k a -&gt; [(k, a)]
</span><a href="../../containers/src/Data.Map.Internal.html#toList"><span class="hs-identifier hs-var">M.toList</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer a
</span><a href="#local-6989586621680940553"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-374"></span><span>
</span><span id="line-375"></span><span class="hs-comment">---</span><span>
</span><span id="line-376"></span><span class="hs-comment">---  Step 3: Fill in the blanks</span><span>
</span><span id="line-377"></span><span class="hs-comment">---</span><span>
</span><span id="line-378"></span><span>
</span><span id="line-379"></span><span class="hs-comment">-- | A FlatSwitchPlan is a list of SwitchPlans, with an integer inbetween every</span><span>
</span><span id="line-380"></span><span class="hs-comment">-- two entries, dividing the range.</span><span>
</span><span id="line-381"></span><span class="hs-comment">-- So if we have (abusing list syntax) [plan1,n,plan2], then we use plan1 if</span><span>
</span><span id="line-382"></span><span class="hs-comment">-- the expression is &lt; n, and plan2 otherwise.</span><span>
</span><span id="line-383"></span><span>
</span><span id="line-384"></span><span class="hs-keyword">type</span><span> </span><span id="FlatSwitchPlan"><span class="annot"><a href="GHC.Cmm.Switch.html#FlatSwitchPlan"><span class="hs-identifier hs-var">FlatSwitchPlan</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SeparatedList"><span class="hs-identifier hs-type">SeparatedList</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchPlan"><span class="hs-identifier hs-type">SwitchPlan</span></a></span><span>
</span><span id="line-385"></span><span>
</span><span id="line-386"></span><span class="annot"><a href="GHC.Cmm.Switch.html#mkFlatSwitchPlan"><span class="hs-identifier hs-type">mkFlatSwitchPlan</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../containers/src/Data.Map.Internal.html#Map"><span class="hs-identifier hs-type">M.Map</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#FlatSwitchPlan"><span class="hs-identifier hs-type">FlatSwitchPlan</span></a></span><span>
</span><span id="line-387"></span><span>
</span><span id="line-388"></span><span class="hs-comment">-- If we have no default (i.e. undefined where there is no entry), we can</span><span>
</span><span id="line-389"></span><span class="hs-comment">-- branch at the minimum of each map</span><span>
</span><span id="line-390"></span><span id="mkFlatSwitchPlan"><span class="annot"><span class="annottext">mkFlatSwitchPlan :: Bool
-&gt; Maybe Label
-&gt; (Integer, Integer)
-&gt; [Map Integer Label]
-&gt; FlatSwitchPlan
</span><a href="GHC.Cmm.Switch.html#mkFlatSwitchPlan"><span class="hs-identifier hs-var hs-var">mkFlatSwitchPlan</span></a></span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; FlatSwitchPlan
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;mkFlatSwitchPlan with nothing left to do&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#empty"><span class="hs-identifier hs-var">empty</span></a></span><span>
</span><span id="line-391"></span><span class="annot"><a href="GHC.Cmm.Switch.html#mkFlatSwitchPlan"><span class="hs-identifier hs-var">mkFlatSwitchPlan</span></a></span><span> </span><span id="local-6989586621680940547"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940547"><span class="hs-identifier hs-var">signed</span></a></span></span><span>  </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940546"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940546"><span class="hs-identifier hs-var">m</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680940545"><span class="annot"><span class="annottext">[Map Integer Label]
</span><a href="#local-6989586621680940545"><span class="hs-identifier hs-var">ms</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-392"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Maybe Label -&gt; Map Integer Label -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#mkLeafPlan"><span class="hs-identifier hs-var">mkLeafPlan</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940547"><span class="hs-identifier hs-var">signed</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Label
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940546"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Integer, Label) -&gt; Integer
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer Label -&gt; (Integer, Label)
forall k a. Map k a -&gt; (k, a)
</span><a href="../../containers/src/Data.Map.Internal.html#findMin"><span class="hs-identifier hs-var">M.findMin</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940543"><span class="hs-identifier hs-var">m'</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Maybe Label -&gt; Map Integer Label -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#mkLeafPlan"><span class="hs-identifier hs-var">mkLeafPlan</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940547"><span class="hs-identifier hs-var">signed</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Label
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940543"><span class="hs-identifier hs-var">m'</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680940543"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940543"><span class="hs-identifier hs-var">m'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Map Integer Label]
</span><a href="#local-6989586621680940545"><span class="hs-identifier hs-var">ms</span></a></span><span> </span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-393"></span><span>
</span><span id="line-394"></span><span class="hs-comment">-- If we have a default, we have to interleave segments that jump</span><span>
</span><span id="line-395"></span><span class="hs-comment">-- to the default between the maps</span><span>
</span><span id="line-396"></span><span class="annot"><a href="GHC.Cmm.Switch.html#mkFlatSwitchPlan"><span class="hs-identifier hs-var">mkFlatSwitchPlan</span></a></span><span> </span><span id="local-6989586621680940542"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940542"><span class="hs-identifier hs-var">signed</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680940541"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940541"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680940540"><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940540"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span id="local-6989586621680940539"><span class="annot"><span class="annottext">[Map Integer Label]
</span><a href="#local-6989586621680940539"><span class="hs-identifier hs-var">ms</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span id="local-6989586621680940538"><span class="annot"><span class="annottext">SwitchPlan
</span><a href="#local-6989586621680940538"><span class="hs-identifier hs-var">p1</span></a></span></span><span class="hs-special">)</span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680940537"><span class="annot"><span class="annottext">[(Integer, SwitchPlan)]
</span><a href="#local-6989586621680940537"><span class="hs-identifier hs-var">ps</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
-&gt; [Map Integer Label] -&gt; [(Integer, SwitchPlan)]
</span><a href="#local-6989586621680940536"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
</span><a href="#local-6989586621680940540"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">[Map Integer Label]
</span><a href="#local-6989586621680940539"><span class="hs-identifier hs-var">ms</span></a></span><span> </span><span class="hs-keyword">in</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SwitchPlan
</span><a href="#local-6989586621680940538"><span class="hs-identifier hs-var">p1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[(Integer, SwitchPlan)]
</span><a href="#local-6989586621680940537"><span class="hs-identifier hs-var">ps</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-397"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-398"></span><span>    </span><span id="local-6989586621680940536"><span class="annot"><span class="annottext">go :: (Integer, Integer)
-&gt; [Map Integer Label] -&gt; [(Integer, SwitchPlan)]
</span><a href="#local-6989586621680940536"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940535"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940535"><span class="hs-identifier hs-var">lo</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940534"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940534"><span class="hs-identifier hs-var">hi</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-399"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940535"><span class="hs-identifier hs-var">lo</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940534"><span class="hs-identifier hs-var">hi</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-400"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940535"><span class="hs-identifier hs-var">lo</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Label -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#Unconditionally"><span class="hs-identifier hs-var">Unconditionally</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940541"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-401"></span><span>    </span><span class="annot"><a href="#local-6989586621680940536"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940533"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940533"><span class="hs-identifier hs-var">lo</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940532"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940532"><span class="hs-identifier hs-var">hi</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940531"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940531"><span class="hs-identifier hs-var">m</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680940530"><span class="annot"><span class="annottext">[Map Integer Label]
</span><a href="#local-6989586621680940530"><span class="hs-identifier hs-var">ms</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-402"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940533"><span class="hs-identifier hs-var">lo</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940529"><span class="hs-identifier hs-var">min</span></a></span><span>
</span><span id="line-403"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940533"><span class="hs-identifier hs-var">lo</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Label -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#Unconditionally"><span class="hs-identifier hs-var">Unconditionally</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940541"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(Integer, SwitchPlan)
-&gt; [(Integer, SwitchPlan)] -&gt; [(Integer, SwitchPlan)]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
-&gt; [Map Integer Label] -&gt; [(Integer, SwitchPlan)]
</span><a href="#local-6989586621680940536"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940529"><span class="hs-identifier hs-var">min</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940532"><span class="hs-identifier hs-var">hi</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940531"><span class="hs-identifier hs-var">m</span></a></span><span class="annot"><span class="annottext">Map Integer Label -&gt; [Map Integer Label] -&gt; [Map Integer Label]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[Map Integer Label]
</span><a href="#local-6989586621680940530"><span class="hs-identifier hs-var">ms</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-404"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940533"><span class="hs-identifier hs-var">lo</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940529"><span class="hs-identifier hs-var">min</span></a></span><span>
</span><span id="line-405"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940533"><span class="hs-identifier hs-var">lo</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Maybe Label -&gt; Map Integer Label -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#mkLeafPlan"><span class="hs-identifier hs-var">mkLeafPlan</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940542"><span class="hs-identifier hs-var">signed</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Label -&gt; Maybe Label
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940541"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940531"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(Integer, SwitchPlan)
-&gt; [(Integer, SwitchPlan)] -&gt; [(Integer, SwitchPlan)]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">(Integer, Integer)
-&gt; [Map Integer Label] -&gt; [(Integer, SwitchPlan)]
</span><a href="#local-6989586621680940536"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940528"><span class="hs-identifier hs-var">max</span></a></span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Integer
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">1</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940532"><span class="hs-identifier hs-var">hi</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Map Integer Label]
</span><a href="#local-6989586621680940530"><span class="hs-identifier hs-var">ms</span></a></span><span>
</span><span id="line-406"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-407"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; [(Integer, SwitchPlan)]
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;mkFlatSwitchPlan&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#integer"><span class="hs-identifier hs-var">integer</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940533"><span class="hs-identifier hs-var">lo</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#integer"><span class="hs-identifier hs-var">integer</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940529"><span class="hs-identifier hs-var">min</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-408"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-409"></span><span>        </span><span id="local-6989586621680940529"><span class="annot"><span class="annottext">min :: Integer
</span><a href="#local-6989586621680940529"><span class="hs-identifier hs-var hs-var">min</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Integer, Label) -&gt; Integer
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer Label -&gt; (Integer, Label)
forall k a. Map k a -&gt; (k, a)
</span><a href="../../containers/src/Data.Map.Internal.html#findMin"><span class="hs-identifier hs-var">M.findMin</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940531"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-410"></span><span>        </span><span id="local-6989586621680940528"><span class="annot"><span class="annottext">max :: Integer
</span><a href="#local-6989586621680940528"><span class="hs-identifier hs-var hs-var">max</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Integer, Label) -&gt; Integer
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer Label -&gt; (Integer, Label)
forall k a. Map k a -&gt; (k, a)
</span><a href="../../containers/src/Data.Map.Internal.html#findMax"><span class="hs-identifier hs-var">M.findMax</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940531"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-411"></span><span>
</span><span id="line-412"></span><span>
</span><span id="line-413"></span><span class="annot"><a href="GHC.Cmm.Switch.html#mkLeafPlan"><span class="hs-identifier hs-type">mkLeafPlan</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../containers/src/Data.Map.Internal.html#Map"><span class="hs-identifier hs-type">M.Map</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="GHC.Cmm.Dataflow.Label.html#Label"><span class="hs-identifier hs-type">Label</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchPlan"><span class="hs-identifier hs-type">SwitchPlan</span></a></span><span>
</span><span id="line-414"></span><span id="mkLeafPlan"><span class="annot"><span class="annottext">mkLeafPlan :: Bool -&gt; Maybe Label -&gt; Map Integer Label -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#mkLeafPlan"><span class="hs-identifier hs-var hs-var">mkLeafPlan</span></a></span></span><span> </span><span id="local-6989586621680940525"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940525"><span class="hs-identifier hs-var">signed</span></a></span></span><span> </span><span id="local-6989586621680940524"><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940524"><span class="hs-identifier hs-var">mbdef</span></a></span></span><span> </span><span id="local-6989586621680940523"><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940523"><span class="hs-identifier hs-var">m</span></a></span></span><span>
</span><span id="line-415"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span id="local-6989586621680940522"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940522"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Map Integer Label -&gt; [(Integer, Label)]
forall k a. Map k a -&gt; [(k, a)]
</span><a href="../../containers/src/Data.Map.Internal.html#toList"><span class="hs-identifier hs-var">M.toList</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940523"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-comment">-- singleton map</span><span>
</span><span id="line-416"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Label -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#Unconditionally"><span class="hs-identifier hs-var">Unconditionally</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940522"><span class="hs-identifier hs-var">l</span></a></span><span>
</span><span id="line-417"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-418"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SwitchTargets -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#JumpTable"><span class="hs-identifier hs-var">JumpTable</span></a></span><span> </span><span class="annot"><span class="annottext">(SwitchTargets -&gt; SwitchPlan) -&gt; SwitchTargets -&gt; SwitchPlan
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
-&gt; (Integer, Integer)
-&gt; Maybe Label
-&gt; Map Integer Label
-&gt; SwitchTargets
</span><a href="GHC.Cmm.Switch.html#mkSwitchTargets"><span class="hs-identifier hs-var">mkSwitchTargets</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940525"><span class="hs-identifier hs-var">signed</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940521"><span class="hs-identifier hs-var">min</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940520"><span class="hs-identifier hs-var">max</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe Label
</span><a href="#local-6989586621680940524"><span class="hs-identifier hs-var">mbdef</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940523"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-419"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-420"></span><span>    </span><span id="local-6989586621680940521"><span class="annot"><span class="annottext">min :: Integer
</span><a href="#local-6989586621680940521"><span class="hs-identifier hs-var hs-var">min</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Integer, Label) -&gt; Integer
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer Label -&gt; (Integer, Label)
forall k a. Map k a -&gt; (k, a)
</span><a href="../../containers/src/Data.Map.Internal.html#findMin"><span class="hs-identifier hs-var">M.findMin</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940523"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-421"></span><span>    </span><span id="local-6989586621680940520"><span class="annot"><span class="annottext">max :: Integer
</span><a href="#local-6989586621680940520"><span class="hs-identifier hs-var hs-var">max</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Integer, Label) -&gt; Integer
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer Label -&gt; (Integer, Label)
forall k a. Map k a -&gt; (k, a)
</span><a href="../../containers/src/Data.Map.Internal.html#findMax"><span class="hs-identifier hs-var">M.findMax</span></a></span><span> </span><span class="annot"><span class="annottext">Map Integer Label
</span><a href="#local-6989586621680940523"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-422"></span><span>
</span><span id="line-423"></span><span class="hs-comment">---</span><span>
</span><span id="line-424"></span><span class="hs-comment">---  Step 4: Reduce the number of branches using ==</span><span>
</span><span id="line-425"></span><span class="hs-comment">---</span><span>
</span><span id="line-426"></span><span>
</span><span id="line-427"></span><span class="hs-comment">-- A sequence of three unconditional jumps, with the outer two pointing to the</span><span>
</span><span id="line-428"></span><span class="hs-comment">-- same value and the bounds off by exactly one can be improved</span><span>
</span><span id="line-429"></span><span class="annot"><a href="GHC.Cmm.Switch.html#findSingleValues"><span class="hs-identifier hs-type">findSingleValues</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#FlatSwitchPlan"><span class="hs-identifier hs-type">FlatSwitchPlan</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#FlatSwitchPlan"><span class="hs-identifier hs-type">FlatSwitchPlan</span></a></span><span>
</span><span id="line-430"></span><span id="findSingleValues"><span class="annot"><span class="annottext">findSingleValues :: FlatSwitchPlan -&gt; FlatSwitchPlan
</span><a href="GHC.Cmm.Switch.html#findSingleValues"><span class="hs-identifier hs-var hs-var">findSingleValues</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#Unconditionally"><span class="hs-identifier hs-type">Unconditionally</span></a></span><span> </span><span id="local-6989586621680940519"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940519"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940518"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940518"><span class="hs-identifier hs-var">i</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#Unconditionally"><span class="hs-identifier hs-type">Unconditionally</span></a></span><span> </span><span id="local-6989586621680940517"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940517"><span class="hs-identifier hs-var">l2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940516"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940516"><span class="hs-identifier hs-var">i'</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#Unconditionally"><span class="hs-identifier hs-type">Unconditionally</span></a></span><span> </span><span id="local-6989586621680940515"><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940515"><span class="hs-identifier hs-var">l3</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680940514"><span class="annot"><span class="annottext">[(Integer, SwitchPlan)]
</span><a href="#local-6989586621680940514"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-431"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940519"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">Label -&gt; Label -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940515"><span class="hs-identifier hs-var">l3</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940518"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Integer
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940516"><span class="hs-identifier hs-var">i'</span></a></span><span>
</span><span id="line-432"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FlatSwitchPlan -&gt; FlatSwitchPlan
</span><a href="GHC.Cmm.Switch.html#findSingleValues"><span class="hs-identifier hs-var">findSingleValues</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer -&gt; Label -&gt; SwitchPlan -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#IfEqual"><span class="hs-identifier hs-var">IfEqual</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940518"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940517"><span class="hs-identifier hs-var">l2</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Label -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#Unconditionally"><span class="hs-identifier hs-var">Unconditionally</span></a></span><span> </span><span class="annot"><span class="annottext">Label
</span><a href="#local-6989586621680940519"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[(Integer, SwitchPlan)]
</span><a href="#local-6989586621680940514"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-433"></span><span class="annot"><a href="GHC.Cmm.Switch.html#findSingleValues"><span class="hs-identifier hs-var">findSingleValues</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940513"><span class="annot"><span class="annottext">SwitchPlan
</span><a href="#local-6989586621680940513"><span class="hs-identifier hs-var">p</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940512"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940512"><span class="hs-identifier hs-var">i</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940511"><span class="annot"><span class="annottext">SwitchPlan
</span><a href="#local-6989586621680940511"><span class="hs-identifier hs-var">p'</span></a></span></span><span class="hs-special">)</span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680940510"><span class="annot"><span class="annottext">[(Integer, SwitchPlan)]
</span><a href="#local-6989586621680940510"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-434"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SwitchPlan
</span><a href="#local-6989586621680940513"><span class="hs-identifier hs-var">p</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940512"><span class="hs-identifier hs-var">i</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(SwitchPlan, Integer) -&gt; FlatSwitchPlan -&gt; FlatSwitchPlan
forall a b. (a, b) -&gt; SeparatedList b a -&gt; SeparatedList b a
</span><a href="GHC.Cmm.Switch.html#consSL"><span class="hs-operator hs-var">`consSL`</span></a></span><span> </span><span class="annot"><span class="annottext">FlatSwitchPlan -&gt; FlatSwitchPlan
</span><a href="GHC.Cmm.Switch.html#findSingleValues"><span class="hs-identifier hs-var">findSingleValues</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SwitchPlan
</span><a href="#local-6989586621680940511"><span class="hs-identifier hs-var">p'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[(Integer, SwitchPlan)]
</span><a href="#local-6989586621680940510"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-435"></span><span class="annot"><a href="GHC.Cmm.Switch.html#findSingleValues"><span class="hs-identifier hs-var">findSingleValues</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940508"><span class="annot"><span class="annottext">SwitchPlan
</span><a href="#local-6989586621680940508"><span class="hs-identifier hs-var">p</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-436"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SwitchPlan
</span><a href="#local-6989586621680940508"><span class="hs-identifier hs-var">p</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-437"></span><span>
</span><span id="line-438"></span><span class="hs-comment">---</span><span>
</span><span id="line-439"></span><span class="hs-comment">---  Step 5: Actually build the tree</span><span>
</span><span id="line-440"></span><span class="hs-comment">---</span><span>
</span><span id="line-441"></span><span>
</span><span id="line-442"></span><span class="hs-comment">-- Build a balanced tree from a separated list</span><span>
</span><span id="line-443"></span><span class="annot"><a href="GHC.Cmm.Switch.html#buildTree"><span class="hs-identifier hs-type">buildTree</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#FlatSwitchPlan"><span class="hs-identifier hs-type">FlatSwitchPlan</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SwitchPlan"><span class="hs-identifier hs-type">SwitchPlan</span></a></span><span>
</span><span id="line-444"></span><span id="buildTree"><span class="annot"><span class="annottext">buildTree :: Bool -&gt; FlatSwitchPlan -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#buildTree"><span class="hs-identifier hs-var hs-var">buildTree</span></a></span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940507"><span class="annot"><span class="annottext">SwitchPlan
</span><a href="#local-6989586621680940507"><span class="hs-identifier hs-var">p</span></a></span></span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SwitchPlan
</span><a href="#local-6989586621680940507"><span class="hs-identifier hs-var">p</span></a></span><span>
</span><span id="line-445"></span><span class="annot"><a href="GHC.Cmm.Switch.html#buildTree"><span class="hs-identifier hs-var">buildTree</span></a></span><span> </span><span id="local-6989586621680940506"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940506"><span class="hs-identifier hs-var">signed</span></a></span></span><span> </span><span id="local-6989586621680940505"><span class="annot"><span class="annottext">FlatSwitchPlan
</span><a href="#local-6989586621680940505"><span class="hs-identifier hs-var">sl</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Integer -&gt; SwitchPlan -&gt; SwitchPlan -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#IfLT"><span class="hs-identifier hs-var">IfLT</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940506"><span class="hs-identifier hs-var">signed</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940504"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; FlatSwitchPlan -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#buildTree"><span class="hs-identifier hs-var">buildTree</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940506"><span class="hs-identifier hs-var">signed</span></a></span><span> </span><span class="annot"><span class="annottext">FlatSwitchPlan
</span><a href="#local-6989586621680940503"><span class="hs-identifier hs-var">sl1</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; FlatSwitchPlan -&gt; SwitchPlan
</span><a href="GHC.Cmm.Switch.html#buildTree"><span class="hs-identifier hs-var">buildTree</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680940506"><span class="hs-identifier hs-var">signed</span></a></span><span> </span><span class="annot"><span class="annottext">FlatSwitchPlan
</span><a href="#local-6989586621680940502"><span class="hs-identifier hs-var">sl2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-446"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-447"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680940503"><span class="annot"><span class="annottext">FlatSwitchPlan
</span><a href="#local-6989586621680940503"><span class="hs-identifier hs-var">sl1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680940504"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940504"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680940502"><span class="annot"><span class="annottext">FlatSwitchPlan
</span><a href="#local-6989586621680940502"><span class="hs-identifier hs-var">sl2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FlatSwitchPlan -&gt; (FlatSwitchPlan, Integer, FlatSwitchPlan)
forall b a.
SeparatedList b a -&gt; (SeparatedList b a, b, SeparatedList b a)
</span><a href="GHC.Cmm.Switch.html#divideSL"><span class="hs-identifier hs-var">divideSL</span></a></span><span> </span><span class="annot"><span class="annottext">FlatSwitchPlan
</span><a href="#local-6989586621680940505"><span class="hs-identifier hs-var">sl</span></a></span><span>
</span><span id="line-448"></span><span>
</span><span id="line-449"></span><span>
</span><span id="line-450"></span><span>
</span><span id="line-451"></span><span class="hs-comment">--</span><span>
</span><span id="line-452"></span><span class="hs-comment">-- Utility data type: Non-empty lists with extra markers in between each</span><span>
</span><span id="line-453"></span><span class="hs-comment">-- element:</span><span>
</span><span id="line-454"></span><span class="hs-comment">--</span><span>
</span><span id="line-455"></span><span>
</span><span id="line-456"></span><span class="hs-keyword">type</span><span> </span><span id="SeparatedList"><span class="annot"><a href="GHC.Cmm.Switch.html#SeparatedList"><span class="hs-identifier hs-var">SeparatedList</span></a></span></span><span> </span><span id="local-6989586621680940500"><span class="annot"><a href="#local-6989586621680940500"><span class="hs-identifier hs-type">b</span></a></span></span><span> </span><span id="local-6989586621680940499"><span class="annot"><a href="#local-6989586621680940499"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680940499"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680940500"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">,</span><span class="annot"><a href="#local-6989586621680940499"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-457"></span><span>
</span><span id="line-458"></span><span id="local-6989586621680940831"><span id="local-6989586621680940832"><span class="annot"><a href="GHC.Cmm.Switch.html#consSL"><span class="hs-identifier hs-type">consSL</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680940832"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621680940831"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SeparatedList"><span class="hs-identifier hs-type">SeparatedList</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680940831"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680940832"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SeparatedList"><span class="hs-identifier hs-type">SeparatedList</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680940831"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680940832"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-459"></span><span id="consSL"><span class="annot"><span class="annottext">consSL :: forall a b. (a, b) -&gt; SeparatedList b a -&gt; SeparatedList b a
</span><a href="GHC.Cmm.Switch.html#consSL"><span class="hs-identifier hs-var hs-var">consSL</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940498"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940498"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680940497"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680940497"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940496"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940496"><span class="hs-identifier hs-var">a'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680940495"><span class="annot"><span class="annottext">[(b, a)]
</span><a href="#local-6989586621680940495"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940498"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680940497"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940496"><span class="hs-identifier hs-var">a'</span></a></span><span class="hs-special">)</span><span class="annot"><span class="annottext">(b, a) -&gt; [(b, a)] -&gt; [(b, a)]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[(b, a)]
</span><a href="#local-6989586621680940495"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-460"></span><span>
</span><span id="line-461"></span><span id="local-6989586621680940828"><span id="local-6989586621680940829"><span class="annot"><a href="GHC.Cmm.Switch.html#divideSL"><span class="hs-identifier hs-type">divideSL</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SeparatedList"><span class="hs-identifier hs-type">SeparatedList</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680940829"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680940828"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Cmm.Switch.html#SeparatedList"><span class="hs-identifier hs-type">SeparatedList</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680940829"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680940828"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621680940829"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Cmm.Switch.html#SeparatedList"><span class="hs-identifier hs-type">SeparatedList</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680940829"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680940828"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-462"></span><span id="divideSL"><span class="annot"><span class="annottext">divideSL :: forall b a.
SeparatedList b a -&gt; (SeparatedList b a, b, SeparatedList b a)
</span><a href="GHC.Cmm.Switch.html#divideSL"><span class="hs-identifier hs-var hs-var">divideSL</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; ((a, [(b, a)]), b, (a, [(b, a)]))
forall a. HasCallStack =&gt; String -&gt; a
</span><a href="../../base/src/GHC.Err.html#error"><span class="hs-identifier hs-var">error</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;divideSL: Singleton SeparatedList&quot;</span></span><span>
</span><span id="line-463"></span><span class="annot"><a href="GHC.Cmm.Switch.html#divideSL"><span class="hs-identifier hs-var">divideSL</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940488"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940488"><span class="hs-identifier hs-var">p</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940487"><span class="annot"><span class="annottext">[(b, a)]
</span><a href="#local-6989586621680940487"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940488"><span class="hs-identifier hs-var">p</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[(b, a)]
</span><a href="#local-6989586621680940486"><span class="hs-identifier hs-var">xs1</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680940485"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940484"><span class="hs-identifier hs-var">p'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[(b, a)]
</span><a href="#local-6989586621680940483"><span class="hs-identifier hs-var">xs2</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-464"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-465"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680940486"><span class="annot"><span class="annottext">[(b, a)]
</span><a href="#local-6989586621680940486"><span class="hs-identifier hs-var">xs1</span></a></span></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940485"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680940485"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940484"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940484"><span class="hs-identifier hs-var">p'</span></a></span></span><span class="hs-special">)</span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680940483"><span class="annot"><span class="annottext">[(b, a)]
</span><a href="#local-6989586621680940483"><span class="hs-identifier hs-var">xs2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; [(b, a)] -&gt; ([(b, a)], [(b, a)])
forall a. Int -&gt; [a] -&gt; ([a], [a])
</span><a href="../../base/src/GHC.List.html#splitAt"><span class="hs-identifier hs-var">splitAt</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[(b, a)] -&gt; Int
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[(b, a)]
</span><a href="#local-6989586621680940487"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Real.html#div"><span class="hs-operator hs-var">`div`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(b, a)]
</span><a href="#local-6989586621680940487"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-466"></span><span>
</span><span id="line-467"></span><span class="hs-comment">--</span><span>
</span><span id="line-468"></span><span class="hs-comment">-- Other Utilities</span><span>
</span><span id="line-469"></span><span class="hs-comment">--</span><span>
</span><span id="line-470"></span><span>
</span><span id="line-471"></span><span id="local-6989586621680940888"><span class="annot"><a href="GHC.Cmm.Switch.html#restrictMap"><span class="hs-identifier hs-type">restrictMap</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">,</span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../containers/src/Data.Map.Internal.html#Map"><span class="hs-identifier hs-type">M.Map</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="#local-6989586621680940888"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../containers/src/Data.Map.Internal.html#Map"><span class="hs-identifier hs-type">M.Map</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integer</span></span><span> </span><span class="annot"><a href="#local-6989586621680940888"><span class="hs-identifier hs-type">b</span></a></span></span><span>
</span><span id="line-472"></span><span id="restrictMap"><span class="annot"><span class="annottext">restrictMap :: forall b. (Integer, Integer) -&gt; Map Integer b -&gt; Map Integer b
</span><a href="GHC.Cmm.Switch.html#restrictMap"><span class="hs-identifier hs-var hs-var">restrictMap</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680940473"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940473"><span class="hs-identifier hs-var">lo</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940472"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940472"><span class="hs-identifier hs-var">hi</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680940471"><span class="annot"><span class="annottext">Map Integer b
</span><a href="#local-6989586621680940471"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Map Integer b
</span><a href="#local-6989586621680940470"><span class="hs-identifier hs-var">mid</span></a></span><span>
</span><span id="line-473"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Map Integer b
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span>   </span><span id="local-6989586621680940469"><span class="annot"><span class="annottext">Map Integer b
</span><a href="#local-6989586621680940469"><span class="hs-identifier hs-var">mid_hi</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Integer -&gt; Map Integer b -&gt; (Map Integer b, Map Integer b)
forall k a. Ord k =&gt; k -&gt; Map k a -&gt; (Map k a, Map k a)
</span><a href="../../containers/src/Data.Map.Internal.html#split"><span class="hs-identifier hs-var">M.split</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940473"><span class="hs-identifier hs-var">lo</span></a></span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Integer
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Map Integer b
</span><a href="#local-6989586621680940471"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-474"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680940470"><span class="annot"><span class="annottext">Map Integer b
</span><a href="#local-6989586621680940470"><span class="hs-identifier hs-var">mid</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Map Integer b
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>      </span><span class="annot"><span class="annottext">Integer -&gt; Map Integer b -&gt; (Map Integer b, Map Integer b)
forall k a. Ord k =&gt; k -&gt; Map k a -&gt; (Map k a, Map k a)
</span><a href="../../containers/src/Data.Map.Internal.html#split"><span class="hs-identifier hs-var">M.split</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621680940472"><span class="hs-identifier hs-var">hi</span></a></span><span class="annot"><span class="annottext">Integer -&gt; Integer -&gt; Integer
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Integer
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Map Integer b
</span><a href="#local-6989586621680940469"><span class="hs-identifier hs-var">mid_hi</span></a></span><span>
</span><span id="line-475"></span><span>
</span><span id="line-476"></span><span class="hs-comment">-- for example: reassocTuples a [(b,c),(d,e)] f == [(a,b),(c,d),(e,f)]</span><span>
</span><span id="line-477"></span><span id="local-6989586621680940840"><span class="annot"><a href="GHC.Cmm.Switch.html#reassocTuples"><span class="hs-identifier hs-type">reassocTuples</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621680940840"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680940840"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span class="annot"><a href="#local-6989586621680940840"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680940840"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680940840"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span class="annot"><a href="#local-6989586621680940840"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span></span><span>
</span><span id="line-478"></span><span id="reassocTuples"><span class="annot"><span class="annottext">reassocTuples :: forall a. a -&gt; [(a, a)] -&gt; a -&gt; [(a, a)]
</span><a href="GHC.Cmm.Switch.html#reassocTuples"><span class="hs-identifier hs-var hs-var">reassocTuples</span></a></span></span><span> </span><span id="local-6989586621680940467"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940467"><span class="hs-identifier hs-var">initial</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621680940466"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940466"><span class="hs-identifier hs-var">last</span></a></span></span><span>
</span><span id="line-479"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940467"><span class="hs-identifier hs-var">initial</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940466"><span class="hs-identifier hs-var">last</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-480"></span><span class="annot"><a href="GHC.Cmm.Switch.html#reassocTuples"><span class="hs-identifier hs-var">reassocTuples</span></a></span><span> </span><span id="local-6989586621680940465"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940465"><span class="hs-identifier hs-var">initial</span></a></span></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span id="local-6989586621680940464"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940464"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680940463"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940463"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">)</span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680940462"><span class="annot"><span class="annottext">[(a, a)]
</span><a href="#local-6989586621680940462"><span class="hs-identifier hs-var">tuples</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680940461"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940461"><span class="hs-identifier hs-var">last</span></a></span></span><span>
</span><span id="line-481"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940465"><span class="hs-identifier hs-var">initial</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940464"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(a, a) -&gt; [(a, a)] -&gt; [(a, a)]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">a -&gt; [(a, a)] -&gt; a -&gt; [(a, a)]
forall a. a -&gt; [(a, a)] -&gt; a -&gt; [(a, a)]
</span><a href="GHC.Cmm.Switch.html#reassocTuples"><span class="hs-identifier hs-var">reassocTuples</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940463"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="annot"><span class="annottext">[(a, a)]
</span><a href="#local-6989586621680940462"><span class="hs-identifier hs-var">tuples</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680940461"><span class="hs-identifier hs-var">last</span></a></span><span>
</span><span id="line-482"></span><span>
</span><span id="line-483"></span><span class="hs-comment">-- Note [GHC.Cmm.Switch vs. GHC.Cmm.Switch.Implement]</span><span>
</span><span id="line-484"></span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-485"></span><span class="hs-comment">-- I (Joachim) separated the two somewhat closely related modules</span><span>
</span><span id="line-486"></span><span class="hs-comment">--</span><span>
</span><span id="line-487"></span><span class="hs-comment">--  - GHC.Cmm.Switch, which provides the CmmSwitchTargets type and contains the strategy</span><span>
</span><span id="line-488"></span><span class="hs-comment">--    for implementing a Cmm switch (createSwitchPlan), and</span><span>
</span><span id="line-489"></span><span class="hs-comment">--  - GHC.Cmm.Switch.Implement, which contains the actual Cmm graph modification,</span><span>
</span><span id="line-490"></span><span class="hs-comment">--</span><span>
</span><span id="line-491"></span><span class="hs-comment">-- for these reasons:</span><span>
</span><span id="line-492"></span><span class="hs-comment">--</span><span>
</span><span id="line-493"></span><span class="hs-comment">--  * GHC.Cmm.Switch is very low in the dependency tree, i.e. does not depend on any</span><span>
</span><span id="line-494"></span><span class="hs-comment">--    GHC specific modules at all (with the exception of Output and</span><span>
</span><span id="line-495"></span><span class="hs-comment">--    GHC.Cmm.Dataflow (Literal)).</span><span>
</span><span id="line-496"></span><span class="hs-comment">--  * GHC.Cmm.Switch.Implement is the Cmm transformation and hence very high in</span><span>
</span><span id="line-497"></span><span class="hs-comment">--    the dependency tree.</span><span>
</span><span id="line-498"></span><span class="hs-comment">--  * GHC.Cmm.Switch provides the CmmSwitchTargets data type, which is abstract, but</span><span>
</span><span id="line-499"></span><span class="hs-comment">--    used in GHC.Cmm.Node.</span><span>
</span><span id="line-500"></span><span class="hs-comment">--  * Because GHC.Cmm.Switch is low in the dependency tree, the separation allows</span><span>
</span><span id="line-501"></span><span class="hs-comment">--    for more parallelism when building GHC.</span><span>
</span><span id="line-502"></span><span class="hs-comment">--  * The interaction between the modules is very explicit and easy to</span><span>
</span><span id="line-503"></span><span class="hs-comment">--    understand, due to the small and simple interface.</span><span>
</span><span id="line-504"></span></pre></body></html>